Skip to content

Commit

Permalink
fix for empty value in meta tag for images, closes #167, closes #166
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnmjones committed Jun 15, 2020
1 parent 5c93dae commit c2e3d37
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/default.py
Expand Up @@ -3,7 +3,7 @@
URICACHE_EXPIRATION = 604800
APPLICATION_LOGLEVEL = "DEBUG"
REQUEST_TIMEOUT = 15
APPLICATION_LOGFILE = '/tmp/mementoembed/mementoembed-application.log'
APPLICATION_LOGFILE = './mementoembed-application.log'
ACCESS_LOGFILE = "/tmp/mementoembed/mementoembed-access.log"
ENABLE_THUMBNAILS = "Yes"
THUMBNAIL_SCRIPT_PATH = "mementoembed/static/js/create_screenshot.js"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.2020.06.05.233456'
release = '0.2020.06.15.234342'


# -- General configuration ---------------------------------------------------
Expand Down
24 changes: 16 additions & 8 deletions mementoembed/imageselection.py
Expand Up @@ -326,9 +326,6 @@ def generate_images_and_scores(baseuri, http_cache, futuressession=None, ignorec

for imageuri in base_image_list:

if 'http://a.fssta.com/content/dam/fsdigital/fscom/BOXING/images/2015/03/16/mitt-romney-evander-holyfield.vresize.1200.675.high.93.jpg' in imageuri:
module_logger.info("imageuri is clearly in body...")

if imageuri not in working_image_list:
working_image_list.append(imageuri)

Expand Down Expand Up @@ -608,7 +605,8 @@ def get_image_from_metadata(uri, http_cache):

try:
metadata_image_url = discovered_fields[0][value_attribute]
metadata_image_url = urljoin( uri, metadata_image_url )
if metadata_image_url != "":
metadata_image_url = urljoin( uri, metadata_image_url )
metadata_images.setdefault(metadata_image_url, []).append('{}="{}" {}'.format(attribute, field, value_attribute))
except KeyError:
module_logger.debug("did not find metadata image URL using value attribute {}...".format(value_attribute))
Expand All @@ -628,19 +626,29 @@ def get_best_scoring_image(uri, http_cache, futuressession=None):
# metadata_image_url, field = get_image_from_metadata(uri, http_cache)
metadata_images = get_image_from_metadata(uri, http_cache)
metadata_image_url = None
if len(metadata_images.keys()) > 0:
metadata_image_url = list(metadata_images.keys())[0]

# if one of the metadata fields is blank, try taking the next
for metadata_image_url in list(metadata_images.keys()):

if metadata_image_url is not None:

if metadata_image_url == "":
metadata_image_url = None
else:
break

if metadata_image_url is not None:

module_logger.debug("metadata_image_url is [{}]".format(metadata_image_url))

r = http_cache.get(metadata_image_url)

if r.status_code == 200:

module_logger.info("discovered image {} with a 200 status code".format(metadata_image_url))
module_logger.debug("discovered metadata image {} with a 200 status code".format(metadata_image_url))

if 'memento-datetime' in r.headers:
module_logger.info("discovered image {} is a memento, returning it".format(metadata_image_url))
module_logger.info("discovered metadata image {} is a memento, returning it".format(metadata_image_url))
return metadata_image_url

else:
Expand Down
2 changes: 1 addition & 1 deletion mementoembed/version.py
@@ -1,3 +1,3 @@
__appname__ = "MementoEmbed"
__appversion__ = '0.2020.06.05.233456'
__appversion__ = '0.2020.06.15.234342'
__useragent__ = "{}/{}".format(__appname__, __appversion__)

0 comments on commit c2e3d37

Please sign in to comment.