-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_speaker_code.py
More file actions
78 lines (60 loc) · 2.37 KB
/
generate_speaker_code.py
File metadata and controls
78 lines (60 loc) · 2.37 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
#!/usr/bin/env python3
import os
import sys
import json
if __name__ == "__main__":
SPACING = " " * 15
original_file = "index.html"
if not os.path.exists(original_file):
print(f"ERROR: index.html not found")
exit(1)
original_content = open(original_file, "r").read()
original_content_begin = original_content.split(f"{SPACING}<!-- SPEAKERS_START -->\n")[0]
original_content_end = original_content.split(f"{SPACING}<!-- SPEAKERS_END -->\n")[1]
speakers = json.loads(open("assets/speakers.json", "r").read())
i = 0
debug=False
generated_code = ""
if len(sys.argv) == 2 and sys.argv[1] == "debug":
debug=True
generated_code+=f"{SPACING}<!-- SPEAKERS_START -->\n"
for name in speakers.keys():
i += 1
bio = speakers[name]['bio'].replace('\n', '</p><p>')
picture = speakers[name]['picture']
project = speakers[name]['project']
image_path = f"./images/speakers/{picture}.jpg"
if not os.path.exists(image_path):
picture = "default"
if debug:
print(f"{image_path} not found")
if debug:
print(f"{name}")
print(f"{image_path}")
print(f"{picture}")
generated_code += f"""{SPACING}<section id="speaker_{i}">
{SPACING}<img class="circular-square" src="images/speakers/{picture}.jpg" alt="{name}"/>
{SPACING}<h3>{name}</h3>
{SPACING}<h4>{project}</h4>
"""
if bio != "":
generated_code += f"""
{SPACING}<ul class="actions">
{SPACING} <li><a id="show_bio_{i}" onclick="showBio({i})" href="#speaker_{i}" class="button scrolly">Read Bio</a></li>
{SPACING}</ul>
{SPACING}<div id="bio_{i}" class="hidden">
{SPACING} <p>{bio}</p>
{SPACING} <ul class="actions">
{SPACING} <li><a id="hide_bio_{i}" onclick="hideBio({i})" href="#speaker_{i}" class="button scrolly">Hide Bio</a></li>
{SPACING} </ul>
{SPACING} </div>
"""
generated_code += f"""
{SPACING}</section>\n"""
if i % 2 == 1:
generated_code += f"{SPACING}<section></section>\n"
generated_code+= f"{SPACING}<!-- SPEAKERS_END -->\n"
new_content = f"{original_content_begin}{generated_code}{original_content_end}"
new_content_file = open(original_file, "w")
new_content_file.write(new_content)
new_content_file.close()