-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
executable file
·36 lines (28 loc) · 911 Bytes
/
generate.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
#!/usr/bin/env python
import json
from string import Template
import logging
logging.basicConfig(level=logging.INFO)
TEMPLATE_FILE = "templates/image.md"
DEST_DIR = "./content/gallery"
def generate_image_page(gallery, title, text, src):
with open(TEMPLATE_FILE, 'r') as tf:
template = Template(tf.read())
result = template.substitute(gallery=gallery, title=title, text=text, src=src)
with open(f"{DEST_DIR}/{src}.md", 'w') as df:
df.write(result)
def generate(gallery):
images = None
with open(f"data/{gallery}.json", 'r') as df:
images = json.load(df)
for image in images:
generate_image_page(gallery, title=image["title"], text=image["text"], src=image["src"])
def main():
generate("my")
generate("other")
if __name__ == "__main__":
try:
main()
except Exception as e:
logging.error(e)
exit(1)