This repository has been archived by the owner on Nov 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cron.py
executable file
·74 lines (52 loc) · 1.84 KB
/
cron.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
#!/usr/bin/env python3
import os
import datetime
import concurrent.futures
import time
import logging
import jinja2
import chronos
def get_year():
y = datetime.datetime.now().year
return y + 2 if datetime.datetime.now().month < 7 else y + 3
STUDENT_PROM = get_year()
ASSISTANT_PROM = STUDENT_PROM - 2
OUTPUT = 'build'
CALDIR = os.path.join(OUTPUT, 'calendars')
GROUPS = ["GRA", "GRB", "APPINGI1", "APPINGI2", "APPINGX1", "APPINGX2",
"APPINGX3"]
MAJORS = ["CSI", "MTI", "GISTRE", "SRS", "SIGL", "SCIA", "TCOM", "GITM"]
def get_calendar(promo, group):
output = '{}/{}.ics'.format(CALDIR, group)
cal = chronos.chronos(promo, group)
with open('{}'.format(output), 'w') as out:
out.writelines(cal)
def update_index():
env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
template = env.get_template('index.html')
groups = [
{'title': 'Groups', 'cals': GROUPS},
{'title': 'Major', 'cals': MAJORS},
]
def name_and_mtime(path):
mtime = time.ctime(os.path.getmtime('{}/{}.ics'.format(CALDIR, path)))
return path, mtime
for group in groups:
group['cals'] = map(name_and_mtime, group['cals'])
output = template.render(groups=groups)
with open(os.path.join(OUTPUT, "index.html"), "w") as f:
f.write(output)
def main():
logging.warning("Started @ {}".format(time.strftime("%c")))
for d in [OUTPUT, CALDIR]:
if not os.path.isdir(d):
os.mkdir(d)
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
for i in MAJORS:
executor.submit(get_calendar, ASSISTANT_PROM, i)
for i in GROUPS:
executor.submit(get_calendar, STUDENT_PROM, i)
update_index()
logging.warning("Finished @ {}".format(time.strftime("%c")))
if __name__ == '__main__':
main()