forked from karel-brinda/tp-zpevnik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vygeneruj_index_surge.py
executable file
·68 lines (49 loc) · 1.32 KB
/
vygeneruj_index_surge.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python3
import sys
import subprocess
import locale
try:
locale.setlocale(locale.LC_ALL,'czech')
except:
locale.setlocale(locale.LC_ALL,'cs_CZ.UTF-8')
cmd='cd output && find . -type f -name "*.pdf" | grep -v "muj_novy_zpevnik"'
def html_pisen(fn):
fn=fn.replace("./","")
return '\n\t<li><a href="{url}">{name}</a></li>'.format(
url=fn,
name=fn.replace("TP_zpevnik_komplet_singles/",""),
)
if __name__ == '__main__':
res=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, universal_newlines=True).stdout.read()
fns=str(res)
fns=fns.split()
fns = sorted(fns, key=locale.strxfrm)
list_tp_zpevniky=[]
list_ostatni_zpevniky=[]
list_singles=[]
for fn in fns:
url=html_pisen(fn)
if fn.find("TP_zpevnik_komplet_singles")!=-1:
list_singles.append(url)
elif fn.find("TP_zpevnik")!=-1:
list_tp_zpevniky.append(url)
else:
list_ostatni_zpevniky.append(url)
html = """
<h3>TP zpěvníky</h3>
<ul>{tp_zpevniky}
</ul>
<h3>Ostatní zpěvníky</h3>
<ul>{ostatni_zpevniky}
</ul>
<h3>Singles</h3>
<ul>{singles}
</ul>
""".format(
tp_zpevniky="".join(list_tp_zpevniky),
ostatni_zpevniky="".join(list_ostatni_zpevniky),
singles="".join(list_singles),
)
with open('index_template.html') as f:
content = f.read()
print(content.replace("##zpevniky##",html))