From b3c1cd57edf3b57357251a3987fd628b07eb440f Mon Sep 17 00:00:00 2001 From: Luca Baffa <47544021+lb803@users.noreply.github.com> Date: Fri, 17 Feb 2023 12:26:17 +0000 Subject: [PATCH] improve get_html_pub_url() method readability --- src/thoth_wrapper.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/thoth_wrapper.py b/src/thoth_wrapper.py index 5208373..84e5e30 100755 --- a/src/thoth_wrapper.py +++ b/src/thoth_wrapper.py @@ -19,17 +19,19 @@ def get_title(thoth_data): def get_html_pub_url(thoth_data): for publication in thoth_data["publications"]: if publication['publicationType'] == 'HTML': - try: - url = publication['locations'][0]['fullTextUrl'] - except IndexError: - raise IndexError('HTML edition defined in Thoth but ' - 'location URL not specified. Please, ' - 'add it and re-run the process.') + locations = publication.get('locations', []) break else: - raise SystemExit('HTML edition data not found in Thoth.', + raise ValueError('HTML edition data not found in Thoth.', 'Please add it and re-run the process.') + try: + url = locations[0]['fullTextUrl'] + except IndexError: + raise IndexError('HTML edition defined in Thoth but ' + 'location URL not specified. Please, ' + 'add it and re-run the process.') + return url def run():