User:Emily/Prototyping/Trimester 03/07

From XPUB & Lens-Based wiki
< User:Emily
Revision as of 23:02, 21 June 2015 by Emily (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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 =, sentence, flags=re.I|re.M)
				if m != None:
	s = random.choice(bag)
	print re.sub(word, word.upper(), s, flags=re.I|re.M)

pick(w, files)

pick("paper", files)