-
Notifications
You must be signed in to change notification settings - Fork 3
/
render.py
41 lines (34 loc) · 1.11 KB
/
render.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
from datetime import datetime
import json
from jinja2 import Environment, Markup
import markdown
from staticjinja import Site
if __name__ == '__main__':
data = json.load(open('html/data.json'))
contexts = [
('index.html', data),
('results.html', data['MIT300']),
('results_CAT2000.html', data['CAT2000']),
('results_COCO-Freeview.html', data['COCO-Freeview']),
]
filters = {}
md = markdown.Markdown()
filters['markdown'] = lambda text: Markup(md.convert(text))
def format_encoded_datetime(datetime_str, format_str):
try:
datetime_obj = datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S.%f')
except ValueError:
datetime_obj = datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S')
return datetime_obj.strftime(format_str)
filters['datetime'] = format_encoded_datetime
site = Site.make_site(
searchpath='./html/templates',
outpath='./html',
contexts=contexts,
filters=filters,
env_kwargs={
'trim_blocks': True,
'lstrip_blocks': True,
}
)
site.render()