Prusa MINI Firmware overview
html2cc Namespace Reference

Functions

def convert (filename)
 

Function Documentation

◆ convert()

def html2cc.convert (   filename)
10 def convert(filename):
11  base, ext = splitext(basename(filename))
12 
13  with open(filename, "br") as src:
14  cdata = src.read()
15  if ext == ".css":
16  cdata = post('https://cssminifier.com/raw',
17  data=dict(input=cdata)).text.encode('utf-8')
18  elif ext == ".js":
19  cdata = post('https://javascript-minifier.com/raw',
20  data=dict(input=cdata)).text.encode('utf-8')
21  elif ext == ".html":
22  cdata = post('https://html-minifier.com/raw',
23  data=dict(input=cdata)).text.encode('utf-8')
24 
25  # cdata = compress(src.read())
26  with open("cc/%s_%s.c" % (base, ext[1:]), "w+") as csource:
27  print("convert %s -> %s" % (src.name, csource.name))
28  csource.write("#include <inttypes.h>\n\n")
29  csource.write("const uint8_t %s_%s[] =\n" % (base, ext[1:]))
30  csource.write("{")
31  col = 0
32  for b in cdata:
33  if col == 0:
34  csource.write("\n\t")
35  elif col % 12 == 0:
36  csource.write(",\n\t")
37  else:
38  csource.write(", ")
39  csource.write("0x%02x" % b)
40  col += 1
41  csource.write("\n};")
42  csource.flush()
43 
44 
html2cc.convert
def convert(filename)
Definition: html2cc.py:10