Created
September 11, 2015 19:55
-
-
Save abeyer/9b4e33bd70a48be71230 to your computer and use it in GitHub Desktop.
splat json data on a jinja2 template from the command line
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 click | |
from jinja2 import Environment, FileSystemLoader, StrictUndefined | |
@click.command() | |
@click.argument('template_file') | |
@click.argument('data_file') | |
def main(template_file, data_file): | |
env = Environment(loader=FileSystemLoader(searchpath='.'), undefined=StrictUndefined) | |
tmpl = env.get_template(template_file) | |
data = json.load(open(data_file)) | |
print tmpl.render(data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment