-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
60 lines (44 loc) · 1.98 KB
/
generator.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
import yaml
import hashlib
from pprint import pprint
def main():
with open("./checklist.yaml", "r") as stream:
data = yaml.safe_load(stream)
with open('templates/index.html') as f:
index = f.read()
with open('templates/section.html') as f:
section_template = f.read()
with open('templates/checklist-item.html') as f:
checklist_item_template = f.read()
image_template = """<img class="img-fluid" src="{{{IMAGE_SRC}}}"/>"""
sections_html = []
for section in data:
section_html = section_template.replace("{{{TITLE}}}", section['title'])
if 'img' in section.keys():
image_html = image_template.replace("{{{IMAGE_SRC}}}", section['img'])
section_html = section_html.replace("{{{IMAGE}}}", image_html)
else:
section_html = section_html.replace("{{{IMAGE}}}", "")
if 'notes' in section.keys():
section_html = section_html.replace("{{{NOTES}}}", section['notes'])
else:
section_html = section_html.replace("{{{NOTES}}}", '')
checklist_items_html = []
for checklist_item in section['checklist']:
checklist_item_html = checklist_item_template.replace("{{{CHECKLIST_ITEM}}}", checklist_item)
checklist_item_html = checklist_item_html.replace("{{{RANDOM_ID}}}", get_ID(section['title'], checklist_item))
checklist_items_html.append(checklist_item_html)
checklist_items_html = "".join(checklist_items_html)
section_html = section_html.replace("{{{ITEM_WRAPPER}}}", checklist_items_html)
sections_html.append(section_html)
sections_html = "".join(sections_html)
index = index.replace("{{{SECTION_LIST}}}", sections_html)
with open('index.html', 'w') as f:
f.write(index)
def get_ID(title, item):
title = ''.join(filter(str.isalnum, title))
item = ''.join(filter(str.isalnum, item))
ID = f"{title}${item}"
return ID
if __name__ == "__main__":
main()