Skip to content
Permalink
Browse files

better support for JSON stories

  • Loading branch information...
shawnmjones committed May 13, 2019
1 parent 9ea926f commit d894d0ddd6530d8af1fc75d58bdc656ea20f69c8
Showing with 43 additions and 3 deletions.
  1. +20 −3 bin/raintale_cmd
  2. +23 −0 test/testinputs/test-story.json
@@ -119,7 +119,7 @@ def process_arguments(args):
)

parser.add_argument('--title', dest='title',
required=True,
required=False,
help="The title used for the story."
)

@@ -220,7 +220,7 @@ def get_storyteller(parser, args):

return storyteller

def format_data(input_filename, title, collection_url, generated_by):
def format_data(input_filename, title, collection_url, generated_by, parser):

story_data = {}

@@ -230,12 +230,27 @@ def format_data(input_filename, title, collection_url, generated_by):

try:
story_data = json.load(f)

if 'title' not in story_data:
parser.error("No story title found in JSON input, a title is required.")
sys.exit(errno.EINVAL)

if title is not None:
logger.warning("overriding title of '{}' from {} with "
"title '{}' supplied as argument".format(
story_data['title'], input_filename, title
))
story_data['title'] = title

except json.JSONDecodeError:

logger.warning("story data is not JSON, attempting to read as "
"a list of memento URLs in a text file")

if title == None:
parser.error("Text file format requires a title be supplied on the command line.")
sys.exit(errno.EINVAL)

f.seek(0)
story_data['title'] = title

@@ -277,6 +292,8 @@ def format_data(input_filename, title, collection_url, generated_by):
)

logger.warning("list of memento URLs has been built successfully")

logger.info("data loaded for story with title {}".format(story_data['title']))

return story_data

@@ -358,7 +375,7 @@ if __name__ == '__main__':
storyteller = get_storyteller(parser, args)
mementoembed_api = choose_mementoembed_api(args.mementoembed_api)
story_template = choose_story_template(args.storyteller, args.storytelling_preset, args.story_template_filename)
story_data = format_data(args.input_filename, args.title, args.collection_url, args.generated_by)
story_data = format_data(args.input_filename, args.title, args.collection_url, args.generated_by, parser)

storyteller.tell_story(story_data, mementoembed_api, story_template)

@@ -0,0 +1,23 @@
{
"title": "My Story Title",
"collection_url": "My Collection URL",
"generated_by": "Generated By",
"elements": [
{
"type": "text",
"value": "Livestream from Oakland which remains hot, gas canisters used, arrests, warnings now about more arrests. \"Chemical agents will be used.\""
},
{
"type": "link",
"value": "http://wayback.archive-it.org/2950/20120510205501/http://www.thenation.com/blog/167643/may-day-special-occupyusa-blog-may-1-frequent-updates/"
},
{
"type": "text",
"value": "For Shame: Hundreds Of Arrests Across the Country Today"
},
{
"type": "link",
"value": "http://wayback.archive-it.org/2950/20120814042704/http://occupyarrests.wordpress.com/"
}
]
}

0 comments on commit d894d0d

Please sign in to comment.
You can’t perform that action at this time.