Skip to content

Commit

Permalink
improve get_html_pub_url() method readability
Browse files Browse the repository at this point in the history
  • Loading branch information
lb803 committed Feb 17, 2023
1 parent c6c8968 commit b3c1cd5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/thoth_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit b3c1cd5

Please sign in to comment.