CoCalc Public Filesmat225-s17 / calendar.html
Author: Jeff Denny
Views : 59
Description: Jupyter html version of mat225-s17/calendar.ipynb
Compute Environment: Ubuntu 18.04 (Deprecated)
calendar

# Create teaching calendar¶

In [7]:
import calendar

In [8]:
# inputs

# year
yr = 2017

# class meeting days
meetingdays = ['M','W','W','F']

# month list in abbreviations

monthlist=['Jan',
'Feb',
'Mar',
'Apr',
'May']
monthlist

Out[8]:
['Jan', 'Feb', 'Mar', 'Apr', 'May']
In [9]:
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 [10]:
final = [['Date','Topic']]
for j in result:
final.append([str(j),' '])

In [11]:
import csv

with open('calendar.csv', 'w') as f2:

writefile = csv.writer(f2)
writefile.writerows(final)


## View the whole year's calendar¶

In [12]:
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 [ ]: