ahoy/tools/esp8266/html/convert.py
lumapu d195eee498 * pinout can be saved using the web setup
* html / css files are now located inside PROGMEM
* conversion of files is done with python script (OS independent, open source)
* moved as much as possible for now to the hm* modules - the app should only be the body
* successfully tested with HM1200
2022-04-25 17:48:12 +02:00

28 lines
1,023 B
Python

import re
def convert2Header(inFile):
outName = "h/" + inFile.replace(".", "_") + ".h"
fileType = inFile.split(".")[1]
f = open(inFile, "r")
data = f.read().replace('\n', '')
f.close()
if fileType == "html":
data = re.sub(r"\>\s+\<", '><', data) # whitespaces between xml tags
data = re.sub(r"(\;|\}|\>|\{)\s+", r'\1', data) # whitespaces inner javascript
data = re.sub(r"\"", '\\\"', data) # escape quotation marks
else:
data = re.sub(r"(\;|\}|\:|\{)\s+", r'\1', data) # whitespaces inner css
define = inFile.split(".")[0].upper()
f = open(outName, "w")
f.write("#ifndef __{}_H__\n".format(define))
f.write("#define __{}_H__\n".format(define))
f.write("const char {}[] PROGMEM = \"{}\";\n".format(inFile.replace(".", "_"), data))
f.write("#endif /*__{}_H__*/\n".format(define))
f.close()
convert2Header("index.html")
convert2Header("setup.html")
convert2Header("hoymiles.html")
convert2Header("style.css")