diff --git a/src/mappings.py b/src/mappings.py index 3bf460a..6c00b84 100644 --- a/src/mappings.py +++ b/src/mappings.py @@ -1,6 +1,8 @@ import json +import logging import re import xml.etree.ElementTree as ET +from os import getenv import odin import pycountry @@ -19,6 +21,9 @@ SourceRef, SourceResource, SourceStructuredDate, SourceSubject) +logger = logging.getLogger() +logger.setLevel(getenv('LOGGING_LEVEL', logging.INFO)) + def identifier_from_uri(uri): """Creates a short UUID. @@ -68,8 +73,12 @@ def convert_dates(value): def has_online_asset(identifier, config): if not config.get('ASSET_BASEURL'): return False - req = requests.head(f"{config['ASSET_BASEURL'].rstrip('/')}/pdfs/{identifier}") - return req.status_code == 200 + try: + req = requests.head(f"{config['ASSET_BASEURL'].rstrip('/')}/pdfs/{identifier}") + return req.status_code == 200 + except Exception as e: + logging.info(e) + return False def has_online_instance(instances, uri, config):