CoCalc Shared Filesmat225-s17 / calendar.ipynbOpen in CoCalc with one click!
Authors: Jeff Denny, William A. Stein
Views : 12
Description: Jupyter notebook mat225-s17/calendar.ipynb

Create teaching calendar

In [1]:
import calendar
In [7]:
# inputs # year yr = 2017 # class meeting days meetingdays = ['M','W','W','F'] # month list in abbreviations #monthlist=['Jan', # 'Feb', # 'Mar', # 'Apr', # 'May'] monthlist=['Aug', 'Sept', 'Oct', 'Nov', 'Dec'] monthlist
['Aug', 'Sept', 'Oct', 'Nov', 'Dec']
In [8]:
result=[] dayindex={'M':0,'T':1,'W':2,'R':3,'F':4} for j in range(len(monthlist)): mycal=calendar.monthcalendar(yr, j+1) mon=monthlist[j] for wk in mycal: for day in meetingdays: if wk[dayindex[day]]!=0: result.append(day+' '+mon+' '+str(wk[dayindex[day]]) )

Write out csv calendar file

In [9]:
final = [['Date','Topic']] for j in result: final.append([str(j),' '])
In [10]:
import csv with open('calendar.csv', 'w') as f2: writefile = csv.writer(f2) writefile.writerows(final)

View the whole year's calendar

In [6]:
print calendar.TextCalendar(calendar.SUNDAY).formatyear(2017, 2, 1, 1, 2)
2017 January February Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 1 2 3 4 8 9 10 11 12 13 14 5 6 7 8 9 10 11 15 16 17 18 19 20 21 12 13 14 15 16 17 18 22 23 24 25 26 27 28 19 20 21 22 23 24 25 29 30 31 26 27 28 March April Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 1 5 6 7 8 9 10 11 2 3 4 5 6 7 8 12 13 14 15 16 17 18 9 10 11 12 13 14 15 19 20 21 22 23 24 25 16 17 18 19 20 21 22 26 27 28 29 30 31 23 24 25 26 27 28 29 30 May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 1 2 3 7 8 9 10 11 12 13 4 5 6 7 8 9 10 14 15 16 17 18 19 20 11 12 13 14 15 16 17 21 22 23 24 25 26 27 18 19 20 21 22 23 24 28 29 30 31 25 26 27 28 29 30 July August Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 1 2 3 4 5 2 3 4 5 6 7 8 6 7 8 9 10 11 12 9 10 11 12 13 14 15 13 14 15 16 17 18 19 16 17 18 19 20 21 22 20 21 22 23 24 25 26 23 24 25 26 27 28 29 27 28 29 30 31 30 31 September October Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 7 3 4 5 6 7 8 9 8 9 10 11 12 13 14 10 11 12 13 14 15 16 15 16 17 18 19 20 21 17 18 19 20 21 22 23 22 23 24 25 26 27 28 24 25 26 27 28 29 30 29 30 31 November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 1 2 5 6 7 8 9 10 11 3 4 5 6 7 8 9 12 13 14 15 16 17 18 10 11 12 13 14 15 16 19 20 21 22 23 24 25 17 18 19 20 21 22 23 26 27 28 29 30 24 25 26 27 28 29 30 31
In [ ]:
In [ ]: