-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_sessions.py
More file actions
71 lines (50 loc) · 2.16 KB
/
generate_sessions.py
File metadata and controls
71 lines (50 loc) · 2.16 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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3.9
import json
from sys import argv
from pathlib import Path
from pprint import pprint
from collections import defaultdict
from paper import Paper
if __name__ == "__main__":
assert len(argv) == 4
template_path: Path = Path(argv[1])
assert template_path.exists()
papers_path: Path = Path(argv[2])
assert papers_path.exists()
# mode: str = argv[3]
# assert mode in ["short", "full"]
dest_path: Path = Path(argv[3])
raw_papers: dict[str, dict]
with open(papers_path, 'r') as pf:
raw_papers = json.load(pf)
# Especially here, we *want* the schedule
all_papers: list[Paper] = [Paper(ignore_schedule=False, **v) for (_, v) in raw_papers.items()]
paired_schedule: defaultdict[str, list[Paper]] = defaultdict(list)
for p in all_papers:
paired_schedule['\n'.join(p.schedule)].append(p)
with open(template_path, 'r') as f:
empty_template: str = f.read()
for session, session_papers in paired_schedule.items():
session_id: str = session.split('\n')[1].split('-')[0]
session_title: str = session.split('\n')[1].split('-')[1].split(':')[1].lstrip().rstrip()
session_time: str = session.split('\n')[0] + ',' + '-'.join(session.split('\n')[1].split('-')[2:])
print(session_id, session_title, session_time)
result: str = empty_template[:]
result = result.replace("SESSION", session_id)
result = result.replace("TITLE", session_title)
result = result.replace("TIME", session_time)
result = result.replace("CHAIRS", session_papers[0].chairs)
for p in session_papers:
result += '''
---
'''
result += f'''
[% .papers %]
{p}
[% / %]
'''
result += f'''
{{{{ youtube('{p.youtube_video_id}') }}}}
'''
with open(dest_path / f"{session_id}.md", 'w') as sink:
sink.write(result)