-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprogram-gen.py
110 lines (93 loc) · 3.48 KB
/
program-gen.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import json
import sys
# Very hack-y. Please don't use! xD
def wrap(content, order):
border = "border-b border-gray-500"
bg = "bg-gray-200" if order % 2 == 0 else ""
class_list = " ".join([bg, border])
return """<div class="flex flex-col py-3 px-2 """ + class_list + """" style="margin-bottom:0 !important;">
""" + content + """
</div>"""
def presentation(talk, section=None, order=0):
authors = None
try:
authors = talk["authors"]
except KeyError as e:
pass
content = "\n".join([presentation_header(talk["time"], section), presentation_detail(talk, authors, section)])
return wrap(content, order)
def break_(talk, section=None, order=0):
content = "\n".join([presentation_header(talk["time"], talk["title"])])
return wrap(content, order)
def presentation_header(time, section):
return """<div class="w-full flex flex-row justify-between">
""" + presentation_section(time) + """
""" + presentation_section(section) + """
</div>"""
def presentation_detail(talk, authors, section):
author_list = presentation_author_list(talk["authors"]) if authors else ""
author = ""
abstract = ""
slides = ""
if author_list != "":
author = """<div class="flex flex-col">
<div class="font-bold">""" + talk["author_type"] + """</div>
<div class="">
""" + author_list + """
</div>
</div>"""
if "abstract" in talk:
abstract = """<div class="flex flex-col">
<div class="font-bold">Abstract</div>
<div class="">
""" + talk["abstract"] + """
</div>
</div>"""
if "slides" in talk:
slides = """<div class="flex flex-col">
<div class="font-bold"><a alt="Slides for """ + talk["title"] + """" href='""" + talk["slides"] + """'>Slides</a></div>
</div>"""
return """
<div class="flex-grow">
<div class="flex flex-col">
""" + presentation_title(talk["title"]) + """
</div>
<div class="space-y-2">
""" + slides + """
""" + author + """
""" + abstract + """
</div>
</div>"""
def presentation_section(section):
return f"<span class=\"text-sm uppercase tracking-wide\">{section}</span>"
def presentation_title(title):
return f"<span class=\"my-4 text-xl font-bold leading-tight\">{title}</span>"
def presentation_author_list(authors):
class_list = ""
return f"<span class=\"{class_list}\">" + f", ".join(authors) + "</span>"
def session(session, title, order=0):
session["title"] = title
content = "\n".join([presentation_header(session["time"], ""), presentation_detail(session, None, None)])
return wrap(content, order)
if __name__ == "__main__":
if len(sys.argv) < 2:
raise Exception("Missing argument: program.json")
program = sys.argv[1]
print("""Title: Program
Description: PyHPC 2020 program
URL: program
Save_as: program/index.html""")
with open(program) as f:
j = json.load(f)
i = 0
for a in j:
i += 1
if a["type"] == "talk":
print(presentation(a, a["section"], order=i))
elif a["type"] == "break":
print(break_(a, order=i))
elif a["type"] == "session":
print(session(a, a["section"], order=i))
for b in a["talks"]:
i += 1
print(presentation(b, section=a["section"], order=i))