-
Notifications
You must be signed in to change notification settings - Fork 5
/
reporting.py
29 lines (23 loc) · 862 Bytes
/
reporting.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
import json
import os
import shutil
import sys
from jinja2 import Template
def generate_reporting(target_user, likes):
# if we don't already have the output folder then create it
# (otherwise we only re-create the HTML page)
output_dir = f"html_output_{target_user}"
if not os.path.isdir(output_dir):
os.mkdir(output_dir)
# load template
with open("index.html", "r", encoding="utf-8") as f:
index_tpl = Template(f.read())
# process template with likes data
index_data = index_tpl.render(likes=likes)
# write HTML output
with open(f"{output_dir}/index.html", "w", encoding="utf-8") as f:
f.write(index_data)
if __name__ == '__main__':
target_user = sys.argv[1]
likes = json.load(open(f"data/likes_{target_user}.json", "r", encoding="utf-8"))
generate_reporting(target_user, likes)