ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
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.

create_gz_files.py 968B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/python3
  2. import os, gzip
  3. # https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
  4. def convert_to_gzip(src, out, f):
  5. input_file = f'{src}{f}'
  6. output_file = f'{out}{f}.gz.h'
  7. output_charp = f'{f.replace(".", "_")}_gz'
  8. top = ''
  9. with open(input_file, 'rb') as f_in:
  10. gz = gzip.compress(f_in.read())
  11. gzlen = len(gz)
  12. top += f'// filename: {f}.gz.h\n'
  13. top += f'#define {output_charp}_len {gzlen}\n'
  14. top += f'const char {output_charp}[] = '
  15. top += '{'
  16. with open(output_file, 'wb') as f_out:
  17. for i, b in enumerate(gz):
  18. if not i%10:
  19. top += '\n '
  20. top += f'0x{b:02X}, '
  21. top = top[:-2]
  22. top += '};'
  23. f_out.write(top.encode(encoding='utf-8'))
  24. src='include/http/'
  25. out='include/'
  26. for f in os.listdir(src):
  27. convert_to_gzip(src, out, f)