-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_papers.py
More file actions
91 lines (69 loc) · 3.39 KB
/
generate_papers.py
File metadata and controls
91 lines (69 loc) · 3.39 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3.9
import json
from sys import argv
from pathlib import Path
# from operator import attrgetter
from paper import Paper
if __name__ == "__main__":
assert len(argv) == 5
template_path: Path = Path(argv[1])
assert template_path.exists()
papers_path: Path = Path(argv[2])
assert papers_path.exists()
dest_path: Path = Path(argv[3])
root_content: Path = Path(argv[4])
raw_papers: dict[str, dict]
with open(papers_path, 'r') as pf:
raw_papers = json.load(pf)
papers: dict[str, Paper] = {k: Paper(**v) for (k, v) in raw_papers.items()}
with open(template_path, 'r') as f:
empty_template: str = f.read()
paper: Paper
for paper in papers.values():
result: str = empty_template[:]
result = result.replace("CONF_ID", paper.id)
result = result.replace("TITLE", paper.title)
result = result.replace("AUTHORS", ", ".join(paper.authors))
result = result.replace("ORID", paper.or_id)
result = result.replace("PDF_URL", paper.pdf)
result = result.replace("ABSTRACT", paper.sanitized_abstract)
result = result.replace("SCHEDULE", "<br>".join(paper.schedule))
if paper.award:
result = result.replace("AWARD", f"## {paper.award}")
else:
result = result.replace("AWARD", "")
result = result.replace("EMBEDEDTEASE", "")
if paper.short:
result = result.replace("PROCEEDINGS", "")
else:
result = result.replace("PROCEEDINGS", f'\n- <a href="{paper.pmlr_url}">Proceedings</a>')
# slides_path: Path = Path(paper.slides)
# if not (root_content / paper.slides[1:]).exists():
# print(f"\tPaper {paper.id} without slides: {paper.url} {(root_content / paper.slides)}")
yt_link = paper.youtube_video_id
slides_ok: bool = (root_content / paper.slides[1:]).exists()
video_ok: bool = yt_link != ""
if video_ok and slides_ok:
result = result.replace("PRESENTATION", f"{{{{ macros.presentation('{yt_link}', '{paper.slides}', 720, 450) }}}}")
# result = result.replace("PRESENTATION", f"{{{{ macros.cloudflare_presentation('{paper.cloudflare_video_id}', '{paper.slides}', 720, 450) }}}}")
# print(f"\tPaper {paper.id} has both slides or presentation.")
elif video_ok and not slides_ok:
result = result.replace("PRESENTATION", f"{{{{ macros.youtube('{yt_link}') }}}}")
# result = result.replace("PRESENTATION", f"{{{{ macros.cloudflare_video('{paper.cloudflare_video_id}') }}}}")
print(f"\tPaper {paper.id} without slides: {(root_content / paper.slides)}")
elif not video_ok and slides_ok:
result = result.replace("PRESENTATION", "Presentation missing")
print(f"\tPaper {paper.id} has no video on YouTube!")
else:
result = result.replace("PRESENTATION", "")
print(f"\tPaper {paper.id} with neither slides or presentation: {(root_content / paper.slides)}")
oral_text: str
if paper.oral:
oral_text = "Oral presentation"
elif paper.poster:
oral_text = "Poster presentation"
elif paper.short:
oral_text = "Short paper"
result = result.replace("ORAL", oral_text)
with open((dest_path / Path(paper.url)).with_suffix(".md"), 'w') as sink:
sink.write(result)