view python/signature.py @ 116:2a83052a7a50

add hg defaults from http://blog.bonardo.net/2010/06/22/so-youre-about-to-use-checkin-needed
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 09 Dec 2010 14:49:14 -0800
parents f3ab51c79813
children
line wrap: on
line source

import random
import sys
import time

from optparse import OptionParser

parser = OptionParser()
parser.add_option('-f', '--file')
parser.add_option('-o', '--output')
(options, args) = parser.parse_args()

if options.file:
    f = file(options.file)    
else:
    f = sys.stdin

lines = [ line.strip() or '\n' for line in f.read().strip().split('\n') ]
content = '\n'.join(lines)
fortunes = [i.strip() for i in content.split('\n\n') ]
f.close()

while 1:
    if options.output:
        f = file(sig, 'w')
        print >> f, random.choice(fortunes)
        f.close()
    else:
        print random.choice(fortunes)
    time.sleep(1)