Skip to content

Instantly share code, notes, and snippets.

@earl
Created July 22, 2008 15:08
Show Gist options
  • Save earl/1065 to your computer and use it in GitHub Desktop.
Save earl/1065 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# earl, 2008-07-22
from __future__ import with_statement
import stringtemplate3, simplejson, sys
def main():
with open(sys.argv[1]) as template_file:
template = stringtemplate3.StringTemplate(template_file.read())
template.attributes = simplejson.load(sys.stdin)
sys.stdout.write(unicode(template).encode('utf-8'))
sys.stdout.flush()
if __name__ == '__main__':
if len(sys.argv) != 2:
from sys import stderr as err
print >> err, 'Usage: %s template' % (sys.argv[0])
print >> err, 'Renders JSON data from stdin through template to stdout.'
sys.exit(64)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment