Output to file

This commit is contained in:
Jake Howard 2017-03-14 19:11:11 +00:00
parent fe8ab3d36c
commit 93c0714d47

View file

@ -1,6 +1,7 @@
from jinja2 import Template
import yaml
import markdown
from io import StringIO
def parse_item(item, h):
@ -19,17 +20,17 @@ def parse_item(item, h):
return item
return markdown.markdown(str(item))
def output(item):
def output(item, f):
item_type = type(item)
if item_type is list:
[output(sub_item) for sub_item in item]
[output(sub_item, f) for sub_item in item]
return
if item_type is dict:
for key, value in item.items():
output(key)
output(value)
output(key, f)
output(value, f)
return
print(item)
f.write(str(item))
with open('test.yml') as f:
@ -38,9 +39,8 @@ with open('test.yml') as f:
raw = template.render()
formatted = list(yaml.load_all(raw))
if len(formatted) > 1:
meta = formatted[0]
for doc in formatted[1:]:
output(parse_item(doc, 1))
else:
output(parse_item(formatted, 1))
with StringIO() as rendered:
output(parse_item(formatted[1], 1), rendered)
with open('test.html', 'w') as f:
f.write(rendered.getvalue())