Skip to content
Permalink
Browse files

new code still works with default template case

  • Loading branch information...
shawnmjones committed Jun 20, 2019
1 parent 6f18d21 commit 5426bb62e7fc8d5d23a3c7d319a42fbb197ff016
Showing with 45 additions and 21 deletions.
  1. +1 −1 README.md
  2. +14 −8 raintale/storytellers/filetemplate.py
  3. +30 −12 raintale/surrogatedata.py
@@ -28,7 +28,7 @@ Raintale supports the following storytellers:
* video - (EXPERIMENTAL) creates an MP4 file containing the top images and sentences from the mementos in your story

Railtale also supports a number of presets for formatting a story for output to a specific file format:
* socialcard - provides a social card like those seen in social networking, may also provide an approximation, depending on file format (html, markdown, mediawiki, and jekyll storytellers)
* default - provides a default set of fields like those seen in the social cards from social networking; may also provide an approximation, depending on file format (html, markdown, mediawiki, and jekyll storytellers)
* thumbnails3col - provides a 3 column layout containing thumbnails of the submitted mementos (HTML storyteller only)
* thumbnails4col - provides a 4 column layout containing thumbnails of the submitted mementos (HTML storyteller only)

@@ -4,7 +4,7 @@
from jinja2 import Environment

from .storyteller import FileStoryteller, get_story_elements
from ..surrogatedata import get_memento_data, get_template_surrogate_fields
from ..surrogatedata import MementoData

module_logger = logging.getLogger('raintale.storytellers.filetemplate')

@@ -27,10 +27,17 @@ def generate_story(self, story_data, mementoembed_api, story_template):
"elements".format(len(story_elements)))

elementcounter = 1
md = MementoData(story_template, mementoembed_api)
# template_surrogate_fields = get_template_surrogate_fields(story_template)

# module_logger.info("template_surrogate_fields: {}".format(template_surrogate_fields))

template_surrogate_fields = get_template_surrogate_fields(story_template)
for element in story_elements:

if element['type'] == 'link':

module_logger.info("template_surrogate_fields: {}".format(template_surrogate_fields))
urim = element['value']
md.add(urim)

for element in story_elements:

@@ -49,10 +56,7 @@ def generate_story(self, story_data, mementoembed_api, story_template):
urim = element['value']
link_data = {}

memento_data = get_memento_data(
template_surrogate_fields,
mementoembed_api,
urim)
memento_data = md.get_memento_data(urim)

module_logger.debug("memento_data: {}".format(memento_data))

@@ -97,8 +101,10 @@ def generate_story(self, story_data, mementoembed_api, story_template):
else:
metadata = None

sanitized_template = md.get_sanitized_template()

env = Environment()
template = env.from_string(story_template)
template = env.from_string(sanitized_template)
rendered_story = template.render(
title=story_data['title'],
generated_by=story_data['generated_by'],
@@ -196,20 +196,19 @@ def _get_field_names_and_preferences(self):

def _get_endpoint_list(self):

# what if the same endpoint appears with different preferences?
# only one call, right?

endpoints = {}

for fieldname,pref in self.fields_and_preferences:

endpoint = self.mementoembed_api + fieldname_to_endpoint[fieldname]
if fieldname not in ['urim', 'creation_time', 'memento_datetime_14num']:

endpoints.setdefault(endpoint, [])

if pref is not None:
if pref not in endpoints[endpoint]:
endpoints[endpoint].append(pref)
endpoint = self.mementoembed_api + fieldname_to_endpoint[fieldname]

endpoints.setdefault(endpoint, [])

if pref is not None:
if pref not in endpoints[endpoint]:
endpoints[endpoint].append(pref)

return endpoints

@@ -278,13 +277,32 @@ def urim_generator(working_list):
def get_memento_data(self, urim, session=None):

if urim not in self.urimlist:
self.urimlist.append(urim)
self.add(urim)

if urim not in self.data:
self.fetch_all_memento_data(session=session)

return self.data[urim]

def get_sanitized_template(self):
# TODO: sanitize the template
pass

template_surrogate_fields = get_template_surrogate_fields(
self.template
)

replacement_list = []

for field in template_surrogate_fields:

if "|prefer " in field:
fieldname = fieldname + " }}"
replacement_list.append( (field, fieldname) )

sanitized_template = self.template

for replacement in replacement_list:
sanitized_template = sanitized_template.replace(replacement[0], replacement[1])

return sanitized_template


0 comments on commit 5426bb6

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