forked from pprobst/okaeri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathokaeri.py
42 lines (32 loc) · 1.04 KB
/
okaeri.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
#!/usr/bin/env python3
import sys
from mako.template import Template
def parse_file(filename="links.oka"):
sections = {}
with open(filename, 'r') as f:
lines = f.readlines()
for line in lines:
if line.startswith("#"):
sect_name = line[2:-1]
sections[sect_name] = []
elif line != "\n":
sections[sect_name].append(line[:-1])
return sections
def create_links(sections):
links = []
for key, val in sections.items():
for s in val:
s = s.split(' ')
links.append((key, s[0], s[1]))
return links
sections = parse_file()
zerudas = create_links(sections)
# Gets theme
if len(sys.argv) == 2:
theme = sys.argv[1]
else:
theme = "train" # default
tmpl = Template(filename='./html/template.html', input_encoding='utf-8', output_encoding='utf-8')
# Creates homepage from template
with open("./html/homepage.html", 'wb') as f_out:
f_out.write(bytes(tmpl.render(zerudas=zerudas, sections=sections, theme=theme)))