-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_html_overview
executable file
·34 lines (26 loc) · 1.24 KB
/
generate_html_overview
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
#!/usr/bin/env python3
#
# Generate the html for the overview page.
import os
import json
import html
import re
import subprocess
def make_prop(p):
return '<div><a href="se-og-stoet-forslag/?Id={id}">{title}</a></div>'.format(
id=p['id'], title=html.unescape(p['title']))
basedir = os.path.dirname(__file__)
fnames = os.listdir(os.path.join(basedir, 'burgerforslag'))
proposals = [json.load(open(os.path.join(basedir, 'burgerforslag', fn)))
for fn in fnames]
proposals.sort(key=lambda p: p['approved'], reverse=True)
proposals = [make_prop(p) for p in proposals]
head = open(os.path.join(basedir, 'templates', 'head.html')).read().format(relpath='')
header = open(os.path.join(basedir, 'templates', 'header.html')).read().format(relpath='/')
newest_commit = subprocess.run(['git', '-C', basedir, 'log', '--pretty=format:%h', 'HEAD^..HEAD'],
stdout=subprocess.PIPE).stdout.decode().strip()
footer = open(os.path.join(basedir, 'templates', 'footer.html')).read().format(
newest_commit=newest_commit)
with open(os.path.join(basedir, 'templates', 'forside.html')) as f:
print(f.read().format(proposals='\n'.join(proposals),
head=head, header=header, footer=footer).rstrip())