-
Notifications
You must be signed in to change notification settings - Fork 1
/
tohtml.py
executable file
·54 lines (44 loc) · 1.45 KB
/
tohtml.py
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
#!/usr/local/bin/python3
"""
Render all tracks from the input into html page.
"""
import argparse
import sys
import os
import track
def write_report(tracks):
os.makedirs('report', exist_ok=True)
with open('report/index.html', 'w') as report:
report.write('<!doctype html>\n')
report.write('<body>\n')
report.write('<table>\n')
report.write('''<tr>
<th>descr<th>S<th>T<th>U<th>D<th>P<th>image
</tr>\n''')
for i, t in enumerate(tracks, start=1):
report.write('<tr><td>%s</td>' % t.path)
report.write('<td>{S}</td><td>{T}</td><td>{U}</td><td>{D}</td><td>{P}</td>'.format(
S=t.path.count('S'),
T=t.path.count('R') + t.path.count('L'),
U=t.path.count('U'),
D=t.path.count('D'),
P=t.count_pillars(),
))
report.write('<td><img src="preview%02d.png"></td>' % i)
report.write('</tr>\n')
t.draw('report/preview%002d.png' % i)
report.write('</table></body>\n')
DESCRIPTION = """\
Take tracks from standard input and print them out to html page.
Each track should be provided on a new line.
"""
def main():
parser = argparse.ArgumentParser(description=DESCRIPTION)
args = parser.parse_args()
tracks = []
for line in sys.stdin:
path = line.strip()
tracks.append(track.Track(path))
write_report(tracks)
if __name__ == '__main__':
main()