Skip to content

Instantly share code, notes, and snippets.

@robbeofficial robbeofficial/
Last active Aug 29, 2015

What would you like to do?
Generates publication lists from JSON data and mustache templates
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
You can’t perform that action at this time.