-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·227 lines (192 loc) · 6.8 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/python
"""#dailymail
##by Chris Jones <cmsj@tenshu.net>
##ported from the original Javascript by Chris Applegate (www.qwghlm.co.uk)
##Released under the GNU GPL v2 or later
----------------------------------------
This is a class with a simple purpose, it creates fictional headlines from the
British newspaper The Daily Mail.
They are well known for their ability to completely suspend all rational
thought and print the craziest nonsense. So crazy that parody is almost
unnecessary, but still a lot of fun.
To use this class, simply pop it somewhere in your python path and do something
like:
import dailymail
paper = dailymail.dailymail()
print paper.headline()
Easy!
(P.S. If you work for the Daily Mail and find this library useful, please let
me know)
"""
import random
class verb(object):
"""Class implementing a verb"""
def __init__(self, plural, singular, tense):
"""Class initialiserr"""
self.singular = singular
self.plural = plural
self.tense = tense
class noun(object):
"""Class implementing a noun"""
def __init__(self, word, person, number):
"""Class initialiser"""
self.word = word
self.person = person
self.number = number
class phrase(object):
"""Class implementing a phrase"""
def __init__(self, present, past, active, target):
"""Class initialiser"""
self.present = present
self.past = past
self.active = active
self.target = target
class dailymail(object):
"""Class implementing basically all of the work the Daily Mail does"""
auxiliary_verbs = [
verb("will", "will", "present"),
verb("could", "could", "present"),
verb("are", "is", "active"),
verb("have", "has", "past"),
]
subjects = [
noun("the labour party",3,1),
noun("brussels",3,1),
noun("the bbc",3,1),
noun("the e.u.",3,1),
noun("the euro",3,1),
noun("the loony left",3,1),
noun("the unions",3,2),
noun("channel 4",3,1),
noun("your local council",3,1),
noun("the french",3,2),
noun("the germans",3,2),
noun("the poles",3,2),
noun("brussels bureaucrats",3,2),
noun("muslims",3,2),
noun("immigrants",3,2),
noun("teachers",3,2),
noun("the unemployed",3,2),
noun("gypsies",3,2),
noun("yobs",3,2),
noun("hoodies",3,2),
noun("feral children",3,2),
noun("chavs",3,2),
noun("the p.c. brigade",3,2),
noun("cyclists",3,2),
noun("foxes",3,2),
noun("asylum seekers",3,2),
noun("gays",3,2),
noun("lesbians",3,2),
noun("single mothers",3,2),
noun("paedophiles",3,2),
noun("working mothers",3,2),
noun("teenage sex",3,1),
noun("political correctness",3,1),
noun("health & safety",3,1),
noun("feminism",3,1),
noun("the metric system",3,1),
noun("dumbing-down",3,1),
noun("rip-off britain",3,1),
noun("the internet",3,1),
noun("facebook",3,1),
noun("twitter",3,1),
noun("filth on television",3,1),
noun("the human rights act",3,1),
noun("the nanny state",3,1),
noun("cancer",3,1),
noun("binge drinking",3,1),
noun("the MMR jab",3,1),
noun("the house price crash",3,1)
]
transitive_phrases = [
phrase("give", "given", "giving", "cancer"),
phrase("give", "given", "giving", "cancer"),
phrase("infect", "infected", "infecting", "with AIDS"),
phrase("give", "given", "giving", "swine flu"),
phrase("make", "made", "making", "obese"),
phrase("give", "given", "giving", "diabetes"),
phrase("make", "made", "making", "impotent"),
phrase("turn","turned","turning","gay"),
phrase("scrounge off","scrounged off","scrounging off",""),
phrase("tax", "taxed", "taxing", ""),
phrase("cheat", "cheated", "cheating", ""),
phrase("defraud", "defrauded", "defrauding", ""),
phrase("steal from","stolen from","stealing from",""),
phrase("burgle","burgled","burgling",""),
phrase("devalue","devalued","devaluing",""),
phrase("rip off","ripped off","ripping off",""),
phrase("molest","molested","molesting",""),
phrase("have sex with","had sex with","having sex with",""),
phrase("impregnate", "impregnated", "impregnating", ""),
phrase("steal the identity of","stolen the identity of","stealing the identity of",""),
phrase("destroy","destroyed","destroying",""),
phrase("kill","killed", "killing",""),
phrase("ruin","ruined","ruining",""),
phrase("hurt","hurt", "hurting","")
]
objects = [
"the british people",
"the middle class",
"middle britain",
"england",
"hard-working families",
"homeowners",
"pensioners",
"drivers",
"taxpayers",
"taxpayers' money",
"house prices",
"property prices",
"britain's farmers",
"the countryside",
"british justice",
"british sovereignty",
"common sense and decency",
"the queen",
"the royal family",
"the church",
"you",
"your mortgage",
"your pension",
"your daughters",
"your children",
"your house",
"your pets",
"the conservative party",
"cliff richard",
"the memory of diana",
"Britain's swans"
]
def match_verb_and_subject(self, subject, verb):
"""Match an auxiliary verb with the subject"""
if subject.number == 1 and subject.person == 3:
return(verb.singular)
else:
return(verb.plural)
def match_verb_and_tense(self, verb, phrase):
"""Match the transitive verb's tense with that of the verb"""
if verb.tense == "present":
return(phrase.present)
elif verb.tense == "past":
return(phrase.past)
elif verb.tense == "active":
return(phrase.active)
def headline(self):
"""Return a randomly generated headline"""
sentence = []
subject = random.choice(self.subjects)
phrase = random.choice(self.transitive_phrases)
verb = random.choice(self.auxiliary_verbs)
target = random.choice(self.objects)
sentence.append(self.match_verb_and_subject(subject, verb))
sentence.append(subject.word)
sentence.append(self.match_verb_and_tense(verb, phrase))
sentence.append(target)
if phrase.target != "":
sentence.append(phrase.target)
final = ' '.join(sentence) + '?'
return(final.upper())
if __name__ == "__main__":
paper = dailymail()
print paper.headline()