Skip to content

Instantly share code, notes, and snippets.

@robbeofficial
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbeofficial/0bd0696f6b5d2d4e7663 to your computer and use it in GitHub Desktop.
Save robbeofficial/0bd0696f6b5d2d4e7663 to your computer and use it in GitHub Desktop.
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