-
Notifications
You must be signed in to change notification settings - Fork 43
/
make-schedule.py
115 lines (97 loc) · 3.37 KB
/
make-schedule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import datetime
import csv
from collections import OrderedDict
# Read in a date in MM/DD/YYYY format and return a string of the form "Dayname, Month dd"
# process_date("03/13/2020") --> "Friday, March 13"
def process_date(date_str):
date_obj = datetime.datetime.strptime(date_str, '%m/%d/%Y')
return date_obj.strftime("%A, %B %d")
with open('header.html') as header_file:
header = header_file.read()
with open('footer.html') as footer_file:
footer = footer_file.read()
print(header)
prolog = '<div class="card mb-12">'
prolog_header = '<div class="card-header"><h4 id="users" class="my-0 font-weight-normal">'
epilog_header = '</h4></div>'
prolog_topic = '<h5><em>'
epilog_topic = '</em></h5>'
prolog_body = '<div class="card-body">'
epilog_body = '</div>'
epilog = '</div>'
rows = {}
with open('schedule.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
d = row['datevalue']
if d != "":
rows[int(d)] = row
rows = OrderedDict(sorted(rows.items()))
for r in rows:
# print(r)
# continue
row = rows[r]
print(prolog)
if row['type'] == 'exam':
print(prolog_header)
print('<font color="red">')
print(process_date(row['date']))
print(f" — {row['topic'].capitalize()}")
print('</font>')
print(epilog_header)
print(prolog_body)
print(prolog_topic)
print(row['paper1'])
print(epilog_topic)
print(epilog_body)
continue
if row['type'] == 'project-due':
print(prolog_header)
print('<font color="red">')
print(process_date(row['date']))
print(f" — <a href=\"{row['url1']}\">{row['topic']}</a>")
print('</font>')
print(epilog_header)
continue
if row['type'] == 'noclass':
print(prolog_header)
print('<font color="red">')
print(process_date(row['date']))
print(" — no class")
print('</font>')
print(epilog_header)
continue
if row['type'] == 'class':
print(prolog_header)
date = row['date']
if date == "":
print("TBD")
else:
print(process_date(row['date']))
print(epilog_header)
print(prolog_body)
print(prolog_topic)
topic = f"{row['topic'].title()}"
print(topic)
print(epilog_topic)
for key in ['1', '2', '3']:
if row['paper'+key] != "":
title = row['paper'+key]
url = row['url'+key]
author = row['author'+key]
if row['status'+key] == "review":
url_str = f'<a href="{url}">{title}</a>, {author} <font color="red">[review]</font><br/>'
elif row['status'+key] == "read":
url_str = f'<a href="{url}">{title}</a>, {author} [read]<br/>'
elif row['status'+key] == "skim":
url_str = f'<a href="{url}">{title}</a>, {author} <font color="darkgreen">[skim]</font><br/>'
# Ignore nextyear
elif row['status'+key] == 'nextyear':
continue
else:
# Default, review
url_str = f'<a href="{url}">{title}</a>, {author} <font color="red">[review]</font><br/>'
print(url_str)
print(epilog_body)
print(epilog)
print(footer)