-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreakHTML.py
More file actions
executable file
·64 lines (50 loc) · 1.49 KB
/
breakHTML.py
File metadata and controls
executable file
·64 lines (50 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
import sys
import string
# Para nodeMCU o maximo deve ser 1700 char
if len(sys.argv) < 1+1:
print("Faltam parâmetros")
print("O uso deve ser: .\\"+ sys.argv[0] +" pageToBreak.hmtl maxCharPerSeg outputFile")
quit()
page_to_break = sys.argv[1]
maxChar = int(sys.argv[2]) if len(sys.argv)>2 else 1700
outfile = sys.argv[3] if len(sys.argv)>3 else "result.lua"
if len(sys.argv) < 1+3:
print("Parâmetros omitidos")
print("Usando como: .\\"+ sys.argv[0] +" "+page_to_break+" "+str(maxChar)+" "+outfile)
with open(page_to_break, 'r') as content_file:
webpage = content_file.read()
i = 0
res = []
while i < len(webpage):
ix = []
ix.append(webpage.find(";", i))
ix.append(webpage.find("\n", i))
ix = min(ix)
if (ix < i):
i = len(webpage)+1
else:
i = ix
res.append(i)
i = i + 1;
with open(outfile, 'w') as result_file:
pass
toBreak = []
j = 0
while j < (max(res)-maxChar):
toBreak.append(max(list(filter(lambda x : x < (maxChar+j) ,res))))
j = toBreak[-1]
toBreak.append(len(webpage))
webpages = ""
with open(outfile, 'a') as result_file:
for key in range(0,len(toBreak)):
result_file.write("webpage"+str(key)+" = [[")
webpages = webpages+"webpage"+str(key)+","
last = toBreak[key]
first = 0 if key == 0 else toBreak[key-1]
result_file.write(webpage[first:last])
result_file.write("\n]]\n")
webpages = webpages[:-1]
result_file.write("response = {")
result_file.write(webpages)
result_file.write("}")