Created
January 31, 2012 15:42
-
-
Save jmora/1711142 to your computer and use it in GitHub Desktop.
This is a short script I wrote years ago to generate a table in mediawiki. I think I'll keep it here, it's easier to find when moving between computers.
This file contains hidden or 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 python | |
import datetime | |
import sys | |
weekday = 3 #3 = Thursday, change it if you will, Monday == 0 | |
def englishMonth(n): #this has to be defined somewhere, but I cannot find it now | |
l = ['January', 'February', 'March', 'April', 'May', 'June', 'July', | |
'August', 'September', 'October', 'November', 'December'] | |
return l[n] | |
def genWikiTable(start, end, step): | |
print('{| border="1"\n! Date !! Place !! Speaker !! Topic\n') | |
d = start | |
while d <= end: | |
print('|-\n! %s %d\n|\n|\n|'%(englishMonth(d.month-1), d.day)) | |
d += step | |
print('|}\n') | |
def genYearWikiTable(year): | |
s = datetime.date(year, 1, 1) | |
while s.weekday() != weekday: | |
s += datetime.timedelta(1) | |
genWikiTable(s, s + datetime.timedelta(51*7), datetime.timedelta(7)) | |
if __name__ == '__main__': | |
if len(sys.argv) > 3: | |
print ('usage: python script.py [year [output_file]]\n'+ | |
' (Thursdays are hardcoded, sorry for that)') | |
exit | |
if len(sys.argv) == 3: | |
sys.stdout = open(sys.argv[2], 'w') | |
elif len(sys.argv) == 1: | |
day = datetime.date.today() | |
sys.argv.append(day.year + 1 if day.month > 10 else 0) | |
genYearWikiTable(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment