Skip to content

Instantly share code, notes, and snippets.

@sansb
Forked from csinchok/gist:5313395
Created April 4, 2013 19:29
Show Gist options
  • Save sansb/5313409 to your computer and use it in GitHub Desktop.
Save sansb/5313409 to your computer and use it in GitHub Desktop.
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