66 lines
1.8 KiB
Python
Executable File
66 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import html, sys
|
|
|
|
titles = {
|
|
'nieuwe-namen': 'nieuwe namen',
|
|
'nieuwe-woorden': 'nieuwe woorden',
|
|
'locaties':'locaties',
|
|
'personen':'personen',
|
|
'organisaties':'organisaties',
|
|
'overige-namen':'andere namen',
|
|
'nieuwe-adjww':'nieuwe adjectieven, deelwoorden en werkwoorden',
|
|
'cat.txt': 'categoriën',
|
|
'tag.txt': 'tags'
|
|
}
|
|
|
|
def e(s):
|
|
return s.replace(''', ''')
|
|
|
|
omt0 = ''' onmouseover="tooltip.show('{} {}')" onmouseout="tooltip.hide()"'''
|
|
omt1 = ''' onmouseover="tooltip.show('{} {}<br><small>{}</small>')" onmouseout="tooltip.hide()" class="tags"'''
|
|
|
|
title = sys.argv[1]
|
|
for key, value in titles.items():
|
|
if sys.argv[1].find(key) >= 0:
|
|
title = value
|
|
break
|
|
|
|
sys.stdout.buffer.write('''<div>
|
|
<h2>{}</h2>
|
|
<table>
|
|
'''.format(html.escape(title)).encode('utf-8'))
|
|
|
|
cols=0
|
|
with open(sys.argv[1], 'rt', encoding='utf-8') as fp:
|
|
lineno = 0
|
|
mx = 0
|
|
for line in fp:
|
|
line = line.strip()
|
|
aa = line.split('\t')
|
|
if len(aa) == 1:
|
|
bb = line.split()
|
|
aa[0] = bb[0]
|
|
aa.append(' '.join(bb[1:]))
|
|
for i in range(1, len(aa)):
|
|
aa[i] = html.escape(aa[i])
|
|
v = int(aa[0])
|
|
if lineno == 0:
|
|
mx = v
|
|
cols=len(aa)
|
|
p = 100 / mx * v
|
|
if len(aa) > 2:
|
|
mo = omt1.format(e(aa[0]), e(aa[1]), e(aa[2]))
|
|
else:
|
|
mo = omt0.format(e(aa[0]), e(aa[1]))
|
|
sys.stdout.buffer.write('<tr{}><td><div style="width:{:.0f}%"></div><td>{}</tr>\n'.format(mo, p, aa[1]).encode('utf-8'))
|
|
lineno += 1
|
|
if lineno == 20:
|
|
break
|
|
while lineno < 20:
|
|
lineno += 1
|
|
sys.stdout.buffer.write(b'<tr><td><div style="width:0%"></div><td> </tr>\n')
|
|
|
|
|
|
sys.stdout.buffer.write(b'</table>\n</div>\n\n')
|