Skip to content

Commit

Permalink
#37 #3 #27 raise error when resolution fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwunderbar666 committed Aug 23, 2023
1 parent 4a00141 commit bd81851
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions flaskinventory/external/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,18 @@ def resolve_doi(doi: str) -> dict:
logger.debug(f'Could not resolve <{doi}> at datacite')
pass

def resolve_authors(authors_tmp: typing.List[dict]) -> typing.List[dict]:
raise requests.HTTPError(f'Could not resolve DOI: <{doi}> at all.')

def resolve_authors(authors_tmp: typing.List[dict],
orcid_token: str=None) -> typing.List[dict]:
"""
Try to get canonical IDs for authors
1. Check if there is an ORCID ID provided and try to get OpenAlex ID
2. Try to query ORCID API to find author candidates
Only adds ORCID ID to cases that are very sure
"""
openalex = OpenAlex()
orcid = ORCID()
orcid = ORCID(token=orcid_token)
for author in authors_tmp:
if 'openalex' in author:
continue
Expand All @@ -321,7 +324,7 @@ def resolve_authors(authors_tmp: typing.List[dict]) -> typing.List[dict]:
author['orcid'] = orcid_id
try:
openalex_id = openalex.get_author_by_orcid(orcid_id)['id'].replace('https://openalex.org/', '')
author['openalex'] = openalex_id
author['openalex'] = [openalex_id]
except requests.HTTPError:
pass
else:
Expand All @@ -334,7 +337,7 @@ def resolve_authors(authors_tmp: typing.List[dict]) -> typing.List[dict]:
author['orcid'] = orcid_details['orcid-id']
try:
openalex_id = openalex.get_author_by_orcid(orcid_details['orcid-id'])['id'].replace('https://openalex.org/', '')
author['openalex'] = openalex_id
author['openalex'] = [openalex_id]
except requests.HTTPError:
pass
except requests.HTTPError:
Expand Down

0 comments on commit bd81851

Please sign in to comment.