{"action":"opened","issue":{"url":"https://api.github.com/repos/aparrish/pytracery/issues/12","repository_url":"https://api.github.com/repos/aparrish/pytracery","labels_url":"https://api.github.com/repos/aparrish/pytracery/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/aparrish/pytracery/issues/12/comments","events_url":"https://api.github.com/repos/aparrish/pytracery/issues/12/events","html_url":"https://github.com/aparrish/pytracery/issues/12","id":150980782,"number":12,"title":"Utility to run pytracery on a JSON file","user":{"login":"hugovk","id":1324225,"avatar_url":"https://avatars.githubusercontent.com/u/1324225?v=3","gravatar_id":"","url":"https://api.github.com/users/hugovk","html_url":"https://github.com/hugovk","followers_url":"https://api.github.com/users/hugovk/followers","following_url":"https://api.github.com/users/hugovk/following{/other_user}","gists_url":"https://api.github.com/users/hugovk/gists{/gist_id}","starred_url":"https://api.github.com/users/hugovk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugovk/subscriptions","organizations_url":"https://api.github.com/users/hugovk/orgs","repos_url":"https://api.github.com/users/hugovk/repos","events_url":"https://api.github.com/users/hugovk/events{/privacy}","received_events_url":"https://api.github.com/users/hugovk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-25T21:07:24Z","updated_at":"2016-04-25T21:07:24Z","closed_at":null,"body":"When building a JSON data file of Tracery grammar, it can be useful to quickly run pytracery on it to get a line or two out:\r\n\r\n```\r\n$ python tracery-demo.py potterpapers.json \r\nHarry Potter and The treatment of complex proximal humeral fractures: analysis of the results of 55 cases treated with PHILOS plate.\r\n\r\n$ python tracery-demo.py potterpapers.json 3\r\nHarry Potter and The fermionic King model\r\nHarry Potter and The fate of the type I non-BPS D7-brane\r\nHarry Potter and The Width of the Colour Flux Tube\r\n```\r\n\r\nA bit like a command-line https://beaugunderson.com/tracery-writer/\r\n\r\nHere's that script:\r\n```python\r\n#!/usr/bin/env python\r\n# encoding: utf-8\r\n\"\"\"\r\nOutput an example line from an input JSON Tracery grammar.\r\n\"\"\"\r\nfrom __future__ import print_function, unicode_literals\r\nimport argparse\r\nimport json\r\n\r\nimport tracery\r\nfrom tracery.modifiers import base_english\r\n\r\nif __name__ == \"__main__\":\r\n    parser = argparse.ArgumentParser(\r\n        description=\"Output an example line from a JSON Tracery grammar.\",\r\n        formatter_class=argparse.ArgumentDefaultsHelpFormatter)\r\n    parser.add_argument(\r\n        \"json\", help=\"Input JSON file\")\r\n    parser.add_argument(\r\n        \"number\", type=int, default=1, nargs=\"?\",\r\n        help=\"Number of lines to generate\")\r\n    args = parser.parse_args()\r\n\r\n    with open(args.json) as data_file:\r\n        rules = json.load(data_file)\r\n\r\n    grammar = tracery.Grammar(rules)\r\n    grammar.add_modifiers(base_english)\r\n\r\n    for i in range(args.number):\r\n        print(grammar.flatten(\"#origin#\"))\r\n\r\n# End of file\r\n```\r\n\r\nI think it might be useful to have something this as a runnable script installed as a part of pytracery.\r\n\r\nWhat do you think?\r\n\r\nIf yes, what's the best way to arrange this? As the `__main__` section of __init__.py? As a separate file?"}}