ESP8266 SHT21 sensor
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

convert-static.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # convert-static.py
  3. #
  4. # This program reads the static html and js files and converts them into
  5. # minified strings defined in a C header file.
  6. #
  7. # ----------------------------------------------------------------------------
  8. # "THE BEER-WARE LICENSE" (Revision 42):
  9. # <xythobuz@xythobuz.de> & <ghost-ghost@web.de> wrote this file. As long as
  10. # you retain this notice you can do whatever you want with this stuff. If we
  11. # meet some day, and you think this stuff is worth it, you can buy us a beer
  12. # in return. Thomas Buck & Christian Högerle
  13. # ----------------------------------------------------------------------------
  14. def fileToString(filename, js = False):
  15. f = open(filename, "r")
  16. sf = ""
  17. for s in f.readlines():
  18. st = s
  19. if js == True:
  20. ss = s.split("//", 1)
  21. if ss[0][-1:] == ':':
  22. st = ss[0] + '//' + ss[1]
  23. else:
  24. st = ss[0]
  25. sf += st
  26. return sf
  27. def minify(text, js = False):
  28. text = text.replace("\r", "")
  29. text = text.replace("\t", "")
  30. text = text.replace(" ", " ")
  31. if js == True:
  32. text = text.replace("\\", "\\\\")
  33. text = text.replace("\n", "\\n")
  34. else:
  35. text = text.replace("\n", " ")
  36. text = text.replace(" ", " ")
  37. text = text.replace(" ", " ")
  38. text = text.replace(" ", " ")
  39. text = text.replace(" ", " ")
  40. text = text.replace(" ", " ")
  41. text = text.replace("> <", "><")
  42. if js == True:
  43. text = text.replace("\\n ", "\\n")
  44. if (text[-1:] == ' '):
  45. text = text[:-1]
  46. return text
  47. def getAsDefine(name, text):
  48. return "#define " + name + " \"" + text.replace("\"", "\\\"") + "\""
  49. template = fileToString("template.html")
  50. template = minify(template)
  51. templates = template.split(" /* %% INSERT_CLIENT_LIST_HERE %% */ ")
  52. print(getAsDefine("HTML_BEGIN", templates[0]))
  53. print(getAsDefine("HTML_END", templates[1]))
  54. js = fileToString("client-script.js", True)
  55. js = minify(js, True)
  56. print(getAsDefine("JS_FILE", js))