User:Emily/Prototyping/Trimester 03/07: Difference between revisions
(Created page with "====Zombie Txt==== This is a simple prototype used for creating a continuous passage based on existed text files, and I want to make it into CGI script which I hope to will he...") |
No edit summary |
||
Line 1: | Line 1: | ||
[[File:Hotpot-literature.jpg|800px]] | |||
This is a simple prototype used for creating a continuous passage based on existed text files, and I want to make it into CGI script which I hope to will help me to make Hybrid Video in the future. | |||
---- | |||
:python script | :python script | ||
<source lang="python"> | <source lang="python"> |
Latest revision as of 22:02, 21 June 2015
This is a simple prototype used for creating a continuous passage based on existed text files, and I want to make it into CGI script which I hope to will help me to make Hybrid Video in the future.
- python script
import re, sys, random
import argparse
w = sys.argv[1]
files = sys.argv[2:]
def pick(word, filepaths):
bag = []
for n in filepaths:
with open(n, "rU") as f:
lines = f.readlines()
for line in lines:
for sentence in line.split("."):
m = re.search(word, sentence, flags=re.I|re.M)
if m != None:
bag.append(sentence.strip()+".")
s = random.choice(bag)
print re.sub(word, word.upper(), s, flags=re.I|re.M)
pick(w, files)
pick("paper", files)