Last active
September 27, 2017 09:36
-
-
Save lordminx/618600de8b1fcf6a5ec2cb3e28e202b2 to your computer and use it in GitHub Desktop.
This file contains 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
"""\ | |
HAPPY CAT - A randomly generated short story in preperation for NaNoGenMo and homage to cybre cats everywhere. | |
""" | |
from random import choice | |
WORD_TARGET = 2000 | |
VOCABULARY = ["maunz", "maunz", "miau", "schnurr", "miez", "hach", "mau", | |
"flausch", "fluffel", "putz", "kraul", "nom", "nomnom", "freu"] | |
def sentence(): | |
"""Sentences are between 10 and 20 words long.""" | |
# Most sentences are around 15 words long. | |
WORD_DIST = [15, 15, 15, 15, 14, 14, 14, 16, 16, 16, 12, 12, 17, 17, 18, 19, 20, 11, 10] | |
words = [choice(VOCABULARY) for x in range(choice(WORD_DIST))] | |
return " ".join(words).capitalize() + choice("....!!?") | |
def paragraph(): | |
"""Paragraphs are between 3 and 5 sentences long.""" | |
SENT_DIST = [4, 4, 4, 3, 5, 2, 1] | |
sentences = [sentence() for x in range(choice(SENT_DIST))] | |
return " ".join(sentences) + "\n\n" | |
def length(string): | |
"""Roughly count words by splitting a string on spaces and count the chunks.""" | |
chunks = string.split(" ") | |
return len(chunks) | |
def story(): | |
"""A story is a bunch of paragraphs long enough to be about 2000 words and a title.""" | |
# use docstring of script as title | |
title = __doc__ | |
story = title + "\n--------\n\n" | |
while length(story) < WORD_TARGET: | |
# Add another paragraph to the story | |
story += paragraph() | |
# Add an ending | |
story += "Maunz." | |
return story | |
if __name__ == "__main__": | |
print(story()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment