-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (28 loc) · 900 Bytes
/
main.py
File metadata and controls
36 lines (28 loc) · 900 Bytes
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
import json
import logging
import os
from datetime import datetime
from jinja2 import Environment, FileSystemLoader
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
def render_index(template_dir, data, output_file):
env = Environment(loader=FileSystemLoader(template_dir))
template = env.get_template("base.html")
with open(data, "r", encoding="utf-8") as f:
cards = json.load(f)
rendered_html = template.render(
cards=cards,
apps=cards,
year=datetime.now().year
)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(rendered_html)
logging.info(f"> Rendered {output_file} with data from {data}")
if __name__ == "__main__":
render_index(
template_dir="templates",
data=os.path.join("data", "data.json"),
output_file="index.html",
)