-
-
Save sansb/5313409 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
import random | |
class Announcement(object): | |
def __init__(self, article): | |
self.grammars['article'] = [article] | |
start = ['"%(article)s" is a %(hyperbole)s, %(name)s!'] | |
grammars = { | |
'hyperbole': [ | |
"Hot Potato", | |
"Screamin' Green Been", | |
"Deviled Egg" | |
], | |
'name': [ | |
'folks', | |
'ladies and gents', | |
'bros and hoes' | |
] | |
} | |
def __getitem__(self, key): | |
if key in self.grammars: | |
return random.choice(self.grammars[key]) | |
else: | |
raise KeyError | |
def __str__(self): | |
return random.choice(self.start) % self | |
announcement = Announcement("Some testing article") | |
print(announcement) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment