-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.py
More file actions
59 lines (48 loc) · 1.92 KB
/
util.py
File metadata and controls
59 lines (48 loc) · 1.92 KB
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
import collections, csv, datetime, io, glob
import requests
SPREADSHEET_URL = "https://docs.google.com/spreadsheets/d/1RH4JnXZZaV78hEnzDC_LRxR5wAsy7qhmTMJzpy8yoy8/pub?gid=0&single=true&output=csv"
def get_lectures_by_year():
r = requests.get(SPREADSHEET_URL)
r.encoding = "utf-8"
f = io.StringIO(r.text)
reader = csv.DictReader(f)
# group lectures by year
lectures_by_year = collections.defaultdict(list)
for row in reader:
year, date = row["year"], row["date"]
if not year:
continue
# attempt to parse date
if date:
try:
dt = datetime.datetime.strptime(date, "%Y-%m-%d")
row["formatted_date"] = dt.strftime("%B %d, %Y")
except:
# standard lectures uses date as an ID
row["formatted_date"] = date
lectures_by_year[year].append(row)
# reverse order of lectures
for y in lectures_by_year:
# make an exception for standard lectures
if y != "Standard":
lectures_by_year[y].reverse()
else:
for l in lectures_by_year[y]:
l["filename"] = f"{l['date']}_{l['title'].replace(' ', '_')}.pdf"
# sort by year in reverse chronological order
return collections.OrderedDict(
sorted(lectures_by_year.items(), reverse=True))
def get_editorials_by_year():
editorials = {}
# sort by year in reverse chronological order
# relies on the implicit insertion order of dictionaries in Python 3
# should probably change to OrderedDict
for fname in sorted(glob.glob("editorials/**/*.pdf", recursive=True), reverse=True):
year, contest, file = fname.split("/")[1:]
if year not in editorials:
editorials[year] = []
editorials[year].append((contest, file))
# reverse order of editorials
for y in editorials:
editorials[y].reverse()
return editorials