Created
February 26, 2014 15:24
-
-
Save busterb/9231513 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import random, sys, os | |
random.seed() | |
nonword = "\n" # Since we split on whitespace, this can never be a word | |
w1 = nonword | |
w2 = nonword | |
# GENERATE TABLE | |
table = {} | |
git_log = os.popen("git log --pretty=oneline --abbrev-commit") | |
for line in git_log: | |
for word in line.split()[1:]: | |
table.setdefault( (w1, w2), [] ).append(word) | |
w1, w2 = w2, word | |
table.setdefault( (w1, w2), [] ).append(nonword) # Mark the end of the file | |
# GENERATE OUTPUT | |
maxwords = int(random.random() * 50) | |
(w1, w2) = random.choice(table.keys()) | |
first = True | |
for i in xrange(maxwords): | |
newword = random.choice(table[(w1, w2)]) | |
if newword == nonword: sys.exit() | |
if first: | |
print(newword.capitalize()), | |
first = False | |
else: | |
print(newword), | |
w1, w2 = w2, newword | |
print "Haha" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment