From 184dfe11f435c163effa4437626f59059457e315 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Thu, 13 May 2021 18:56:43 +0200 Subject: [PATCH] add combiner script --- combiner.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 combiner.py diff --git a/combiner.py b/combiner.py new file mode 100755 index 0000000..c7a24c0 --- /dev/null +++ b/combiner.py @@ -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 "" in l or "" 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");