forked from baidut/PatchVQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (49 loc) · 1.64 KB
/
main.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
"""generate html website code"""
# python main.py pvq.ini PatchVQ
# %%
import sys
from jinja2 import Environment, BaseLoader, FileSystemLoader, Template
import pyperclip
import random
import pandas as pd
import configparser
import webbrowser
import os
def main(ini_file, target='DEFAULT'):
c = configparser.ConfigParser()
c.read(ini_file)
# c.read('amt.ini')
cfg = dict(c[target].items())
# cfg that ends with 's' (multiple items)
# for x in ['phases', 'include_pages', 'addons','train_vids', 'label_vids', 'sample_vids', 'gold_vids', 'backup_vids']:
# if cfg[x].strip() != '':
# cfg[x] = cfg[x].strip().split('\n')
# else:
# cfg[x] = []
for k in cfg.keys():
cfg[k] = cfg[k].replace('"', '"')
# with open("./template.htm") as f: template_str = f.read()
# template = Environment(loader=FileSystemLoader("./")).from_string(template_str)
template = Environment(loader=FileSystemLoader("./")).from_string("""
{% for sec in sections.split(',') %}
{% include sec.strip()+'.htm' %}
{% endfor %}
""")
rendered = template.render(**cfg)
if cfg['out_html'] == 'clipboard':
pyperclip.copy(rendered)
else:
dir = 'file://' + os.path.dirname(os.path.realpath(__file__))
html_file = cfg['out_html'] if os.path.isabs(cfg['out_html']) else dir + os.path.sep + cfg['out_html']
with open(cfg['out_html'], "w") as f:
f.write(rendered)
"""
# %%
!pip install pyperclip
!python main.py video debugNoBackup
!python main.py video jerry
# %%
"""
# %%
if __name__ == "__main__":
main(ini_file= sys.argv[1], target=sys.argv[2])