10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-26 06:14:38 +01:00
QUESTDB_website/tools/generate_data.py

42 lines
982 B
Python
Raw Normal View History

2020-11-16 12:44:21 +01:00
#!/usr/bin/env python3
import os
import os.path
import json
2020-11-25 01:52:53 +01:00
2020-11-16 12:44:21 +01:00
def main():
2020-11-25 01:52:53 +01:00
baseURL = "/"
with open("config.toml","r") as f:
for line in f.readlines():
if line.startswith("baseURL"):
baseURL = line.split('=')[1].strip()[1:-1]
break
if baseURL.startswith("http"):
baseURL = '/'+baseURL.split('/')[3]+'/'
print (baseURL)
2020-11-16 12:44:21 +01:00
d = {}
os.chdir("static")
try:
os.remove(os.path.join("data","database.json"))
except FileNotFoundError:
pass
for root, dirs, files in os.walk('data'):
for name in files:
filename = os.path.join(root,name)
with open(filename,'r',encoding="utf8") as f:
try:
2020-11-25 01:52:53 +01:00
d[baseURL+filename] = f.read()
2020-11-16 12:44:21 +01:00
except UnicodeDecodeError:
pass
with open(os.path.join("data","database.json"),'w') as f:
f.write(json.dumps(d,indent=1))
if __name__ == "__main__":
main()