-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.py
44 lines (34 loc) · 1.21 KB
/
core.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
import json
import webbrowser
import abbrs
import pandas as pd
def read_schedule(filename: str) -> (str, str):
dat = pd.read_excel(filename)
date_col_name = dat.columns[0]
current_date = None
events = [ ]
for _, row in dat.iterrows():
row = row.to_dict()
date = row[date_col_name].strftime("'%Y-%m-%d'")
del row[date_col_name]
for key, val in row.items():
if pd.notna(val):
title = json.dumps(f'{key}:{val}', ensure_ascii=False)
events.append(f'''{{
title: {title},
start: {date}
}}''')
if current_date == None:
current_date = date
return ',\n'.join(events), current_date.replace("'", '')
def render(filename: str) -> None:
OUT = './calendar-20/out.html'
events_str, current_date = read_schedule(filename)
template = abbrs.read_file('calendar-20/template.html')
template = template.replace('TODAY_STR', current_date).replace('EVENTS_STR', events_str)
abbrs.write_file(OUT, template)
webbrowser.open(OUT)
if __name__ == '__main__':
FILE = './calendar.xls'
print(f'Parsing f{FILE}.')
render(FILE)