add combiner script

This commit is contained in:
Yannik Schmidt
2021-05-13 18:56:43 +02:00
parent cdb3449931
commit 184dfe11f4

65
combiner.py Executable file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/python3
import requests
import os
TARGET_DIV = "mobile-display"
TARGET_DIR = "/home/ik15ydit/reps/ths-website-full"
# "php-file" : "flask-url"
MAP = {
"impressum.php" : "/impressum",
"datenschutz.php" : "/impressum",
"schimmel.php" : "/content/?id=gebaeude-schimmel",
"gebaeudecheck.php" : "/content/?id=gebaeude-gebaeudecheck",
"luftdichtheit.php" : "/content/?id=gebaeude-luftdichtheit",
"index.php" : "/",
"kontakt.php" : None,
"leckageortung.php" : "/content/?id=wasserschaeden-leckageortung",
"leitunsgsortung.php" : "/content/?id=wasserschaeden-leitungsortung",
"schaltanlagen.php" : "/content/?id=anlagen-elektronik-schaltanlagen",
"elektronik.php" : "/content/?id=anlagen-elektronik-elektronik",
"technologie.php" : "/content/?id=technologie",
"trocknung.php" : None
}
for key, value in MAP.items():
if value:
# create new mobile section #
phpFile = os.path.join(TARGET_DIR, key)
response = requests.get("http://localhost:5000" + value)
mobileFile = os.path.join(TARGET_DIR, key[:-4]) + "-mobile.php"
with open(mobileFile, "w") as f:
f.write(response.content.decode("utf-8"))
# read old toplevel file #
contentNew = []
with open(os.path.join(TARGET_DIR, key), "r") as f:
foundStart = False
for l in f:
# look for start #
if not foundStart:
if "mobile-display" in l:
foundStart = True
else:
continue
# skip end
if "</body>" in l or "</html>" in l:
continue
contentNew += [l]
if "footerbereich" in l:
contentNew += [ "require('{}');\n".format(key[:-4] + "-mobile.php") ]
contentNew += [ "require('module/endhtml.php');\n" ]
# write updated toplevel file
with open(os.path.join(TARGET_DIR, key), "w") as f:
f.write("".join(contentNew))
if not value:
with open(os.path.join(TARGET_DIR, key), "a") as f:
f.write("require('module/endhtml.php')\n");