Skip to content

Instantly share code, notes, and snippets.

Last active Dec 19, 2017
What would you like to do?
Calendar Facts
#!/usr/bin/env python3
# Data source:
import random
import re
class Or(list):
def __init__(self, *args):
super(Or, self).__init__(args)
def generate(x):
if type(x) is str:
return x
if type(x) is Or:
return generate(random.choice(x))
return str.join(' ', map(generate, x))
result = generate([
'Did you know that',
['the', Or('Fall', 'Spring'), 'equinox'],
['the', Or('Winter', 'Summer'), Or('solstice', 'Olympics')],
['the', Or('earliest', 'latest'), Or('sunrise', 'sunset')],
['daylight', Or('saving', 'savings'), 'time'],
['leap', Or('year', 'day')],
['the', Or('harvest', 'super', 'blood'), 'moon'],
'Toyota Truck Month',
'Shark Week'
['happens', Or('earlier', 'later', 'at the wrong time'), 'every year'],
'drifts out of sync with the',
[Or('Gregorian', 'Mayan', 'Lunar', 'iPhone'), 'calendar'],
'atomic clock in Colorado'
['might', Or('not happen', 'happen twice'), 'this year']
'because of',
['time zone legislation in', Or('Indiana', 'Arizona', 'Russia')],
'a decree by the pope in the 1500s',
'of the',
'Earth\'s axis',
'prime meridian',
[Or('international date', 'mason-dixon'), 'line'],
'magnetic field reversal',
['an arbitrary decision by ', Or('Benjamin Franklin', 'Isaac Newton', 'FDR')]
'? Apparently,',
'it causes a predictable increase in car accidents',
'that\'s why we have leap seconds',
'that\'s why we have leap seconds',
'it was even more extreme during the',
Or('Bronze Age', 'Ice Age', 'Cretaceous', '1990s')
'there\'s a proposal to fix it, but it',
'will never happen',
'actually makes things worse',
'is stalled in congress',
'might be unconstitutional'
'it\'s getting worse and no one knows why'
'While it may seem like trivia, it',
'causes huge headaches for software developers',
'is taken advantage of by high-speed traders',
'triggered the 2003 Northeast Blackout',
'has to be corrected for by GPS satellites',
'is now recognized as a major cause of World War I'
print(re.sub(r' ([.?])', r'\1', result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment