-
Notifications
You must be signed in to change notification settings - Fork 2
/
html.py
36 lines (28 loc) · 1.05 KB
/
html.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
import os
import yaml
import basic
CUSTOM_DIR_PATH = 'custom'
DATA_DIR_PATH = 'data'
def tryInt(any):
try: return int(any)
except: return None
def process(customDirPath, dataDirPath):
print('--html--')
htmlContent = []
templateFile = open(os.path.join(dataDirPath, 'template.html'), 'r', encoding='utf-8')
templateContent = templateFile.read()
templateFile.close()
templateContent = templateContent.replace('<?=customDirPath?>', customDirPath)
configFile = open(os.path.join(customDirPath, 'config.yml'), 'r', encoding='utf-8')
configContent = configFile.read()
configFile.close()
configContent = yaml.safe_load(configContent)
htmlContent = basic.magicTagReplace(templateContent, configContent, removeLineWhenMissingData=True)
outputFile = open('index.html', 'w+', encoding='utf-8')
outputFile.write(htmlContent)
outputFile.close()
if __name__ == '__main__':
if len(os.sys.argv) > 1:
process(os.sys.argv[1], DATA_DIR_PATH)
else:
process(CUSTOM_DIR_PATH, DATA_DIR_PATH)