Last active
August 29, 2015 13:56
-
-
Save dtlanghoff/9099169 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
#!/usr/bin/env python3 | |
import codecs | |
import datetime | |
class Day: | |
def __init__(self, name, date): | |
self.name = name | |
self.date = date | |
def __str__(self): | |
return u'%s %s' % (self.name, formatdate(self.date)) | |
def __cmp__(self, other): | |
if isinstance(other, Day): | |
return cmp(self.date, other.date) | |
else: | |
return cmp(self.date, other) | |
def _is_leap_year(self, year): | |
if year % 400 == 0: | |
return True | |
elif year % 100 == 0: | |
return False | |
elif year % 4 == 0: | |
return True | |
else: | |
return False | |
def _next_leap_year(self, year): | |
if _is_leap_year((year//4+1)*4): | |
return (year//4+1)*4 | |
else: | |
return (year//4+2)*4 | |
def next_anniversary(self, date=None): | |
if date == None: | |
date = datetime.date.today() | |
if not (self.date.month == 2 and self.date.day == 29): | |
if date > datetime.date(date.year, self.date.month, self.date.day): | |
return datetime.date(date.year + 1, self.date.month, self.date.day) | |
else: | |
return datetime.date(date.year, self.date.month, self.date.day) | |
else: | |
if self._is_leap_year(date.year) and ((date.month, date.day) <= (2, 29)): | |
return datetime.date(date.year, 2, 29) | |
else: | |
return datetime.date(self._next_leap_year(date.year), 2, 29) | |
def is_semicentennial(self, year=None): | |
if year == None: | |
year = datetime.date.today().year | |
return (year - self.date.year) % 50 == 0 | |
def parsedate(s): | |
return datetime.datetime.strptime(s, '%Y-%m-%d').date() | |
def formatdate(d): | |
return d.isoformat() | |
def load(filename): | |
with codecs.open('days.tsv', encoding='utf-8') as f: | |
days = sorted([Day(l.split('\t')[0], parsedate(l.split('\t')[1].strip())) for l in f.readlines()], key=lambda d: d.date) | |
return days |
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
Charles Darwin | 1809-2-12 | |
---|---|---|
Alan Turing | 1912-6-23 | |
Sigmund Freud | 1856-5-6 | |
Dr. Seuss | 1904-3-2 | |
Stephen Hawking | 1942-1-8 | |
Bill Gates | 1955-10-28 | |
Bill Nye | 1955-11-27 | |
Abraham Lincoln | 1809-2-12 | |
Walt Disney | 1901-12-5 | |
Neil Armstrong | 1930-8-5 | |
Albert Einstein | 1879-3-14 | |
Winston Churchill | 1874-11-30 | |
Mohandas Gandhi | 1869-10-2 | |
Martin Luther | 1483-11-10 | |
Martin Luther King, Jr. | 1929-1-15 | |
Anne Frank | 1929-6-12 | |
Adolf Hitler | 1889-4-20 | |
Galileio Gailei | 1564-2-15 | |
Nicolaus Copernicus | 1473-2-19 | |
Kim Jong-il | 1941-2-16 | |
Kim Jong-un | 1983-1-8 | |
Kim Il-sung | 1912-4-15 | |
Satoru Iwata | 1959-12-6 | |
Shigeru Miyamoto | 1952-11-16 | |
Benedict XVI | 1927-4-16 | |
Francis I | 1936-12-17 | |
Knut Jørgen Røed Ødegaard | 1966-5-6 | |
Schrödinger | 1887-8-12 | |
Wolfgang Amadeus Mozart | 1756-1-27 | |
Ludwig van Beethoven | 1770-12-17 | |
Johann Sebastian Bach | 1750-7-28 | |
Frédéric Chopin (Official) | 1810-2-22 | |
Frédéric Chopin (Own usage) | 1810-3-1 | |
Charlie Chaplin | 1889-4-16 | |
George Frideric Händel | 1685-2-23 | |
Fridthjov Anderssen | 1876-4-26 | |
Harald V | 1937-2-21 | |
Olav V | 1903-7-2 | |
Haakon VII | 1872-8-3 | |
Pablo Picasso | 1881-10-25 | |
Vincent van Gogh | 1853-3-30 | |
Edvard Grieg | 1843-6-15 | |
Edvard Munch | 1863-12-12 | |
Leonardo da Vinci | 1452-4-15 | |
Elizabeth II | 1926-4-21 | |
Elizabeth I | 1533-9-7 | |
Franz Ferdinand | 1863-12-18 | |
Peter the Great | 1672-6-9 | |
Joseph Stalin | 1878-12-18 | |
Vladimir Lenin | 1870-4-22 | |
Vladimir Putin | 1952-10-7 | |
Michelangelo | 1475-3-6 | |
Carl Barks | 1901-3-27 | |
Don Rosa | 1951-6-29 | |
Bob Ross | 1942-10-29 | |
Jim Henson | 1936-9-24 | |
Barack Obama | 1961-8-4 | |
Thomas Jefferson | 1743-4-13 | |
John Cleese | 1939-10-27 | |
George Washington | 1732-2-22 | |
John Lennon | 1940-10-9 | |
Paul McCartney | 1942-6-18 | |
Ringo Starr | 1940-7-7 | |
George Harrison | 1943-2-25 | |
Elvis Presley | 1935-1-8 | |
Steve Jobs | 1955-2-24 | |
Gabe Newell | 1962-11-3 | |
Mark Zuckerberg | 1984-5-14 | |
H.G. Wells | 1866-9-21 | |
George Orwell | 1903-6-25 | |
Henrik Ibsen | 1828-3-20 | |
Leo Tolstoy | 1828-9-9 | |
Fyodor Dostoyevsky | 1821-11-11 | |
John Green | 1977-8-24 | |
J.R.R. Tolkien | 1892-1-3 | |
J.K. Rowling | 1965-7-31 | |
Ian Fleming | 1908-5-28 | |
Lewis Carroll | 1832-1-27 | |
C.S. Lewis | 1898-11-29 | |
Charles Dickens | 1812-2-7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment