-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_assembler.py
54 lines (40 loc) · 1.8 KB
/
app_assembler.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
import os
def main():
version = "v2.1.0"
res_folder = "transcriptions"
template_app_file_path = "template_app.html"
template_python_main_script_file_path = "template_python_main_script.py"
brython_script_file_path = "deps/Brython-3.9.0/brython.min.js"
app_file_path = f"webapp/replicator_{version}.html"
github_app_file_path = "index.html"
transcriptions_scripts = []
for file_name in next(os.walk(res_folder))[2]:
file_path = os.path.join(res_folder, file_name)
name = os.path.splitext(file_name)[0]
with open(file_path, "r", encoding='utf-8') as f:
text = f.read()
transcription_script = f'''\
"{name}": {{
"text": """\\
{text}"""
}},
'''
transcriptions_scripts.append(transcription_script)
transcriptions_script = "".join(transcriptions_scripts)
with open(template_python_main_script_file_path, "r", encoding='utf-8') as f:
template_python_main_script = f.read()
python_main_script = template_python_main_script.replace("##RAW_TRANSCRIPTIONS##", transcriptions_script)
python_main_script = python_main_script.replace("##VERSION##", version)
with open(brython_script_file_path, "r", encoding='utf-8') as f:
brython_script = f.read()
with open(template_app_file_path, "r", encoding='utf-8') as f:
template_app_script = f.read()
app_script = template_app_script.replace("##PYTHON_MAIN_SCRIPT##", python_main_script)
app_script = app_script.replace("##VERSION##", version)
app_script = app_script.replace("<!--##BRYTHON_SCRIPT##-->", brython_script)
with open(app_file_path, "w", encoding='utf-8') as f:
f.write(app_script)
with open(github_app_file_path, "w", encoding='utf-8') as f:
f.write(app_script)
if __name__ == '__main__':
main()