Last active
August 29, 2015 14:26
-
-
Save robbeofficial/0bd0696f6b5d2d4e7663 to your computer and use it in GitHub Desktop.
Generates publication lists from JSON data and mustache templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import pystache | |
# read template | |
template = open('template.mustache','r').read() | |
# ignore line breaks and parse \n instead | |
template = ''.join(template.splitlines()).decode('string_escape') | |
# load publications JSON | |
publications = json.load(open('publications.json','r')) | |
# render | |
f = open('rendered.txt','w') | |
for publication in publications: | |
# generate authors list from json array | |
authors = '' | |
for author in publication['author']: | |
authors += author['firstName'] + " " + author['lastName'] + ", " | |
publication['authors'] = authors[:-2] | |
f.write(pystache.render(template, publication).encode('utf8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment