forked from physiopy/physiopy-codesprint-spring2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
executable file
·33 lines (26 loc) · 858 Bytes
/
generator.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
from jinja2 import Environment, FileSystemLoader
import os
import simplejson as json
def load_json(filename):
"""Load data from a json file
Parameters
----------
filename : str
Filename to load data from.
Returns
-------
data : dict
"""
with open(filename, 'r') as fp:
data = json.load(fp)
return data
files_to_generate = [{"filename": "index.html.tmpl", "location":"./"},
{"filename": "css/stylish-portfolio.css.tmpl", "location": "./"}]
env = Environment(loader=FileSystemLoader('./'))
info = load_json("data.json")
for f in files_to_generate:
template = env.get_template(f["filename"])
outfile = os.path.join(f["location"], f["filename"].replace(".tmpl",""))
print("writing", outfile)
with open(outfile, "w") as q:
q.write(template.render(**info))