SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 6759f25a authored by Boris Ponsioen's avatar Boris Ponsioen
Browse files

Readds error handling in get_crossref_test temporarily

parent 41137ffa
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,8 @@ def get_crossref_test(cursor='*'): ...@@ -39,6 +39,8 @@ def get_crossref_test(cursor='*'):
number_of_results = len(r_json['message']['items']) number_of_results = len(r_json['message']['items'])
citables = [parse_crossref_citable(it) for it in citables_json] citables = [parse_crossref_citable(it) for it in citables_json]
# Parser returns None if there's an error
errors = any([not i for i in a if not i])
citables = [citable for citable in citables if citable is not None] citables = [citable for citable in citables if citable is not None]
# Mass insert in database (will fail on encountering existing documents # Mass insert in database (will fail on encountering existing documents
...@@ -46,8 +48,10 @@ def get_crossref_test(cursor='*'): ...@@ -46,8 +48,10 @@ def get_crossref_test(cursor='*'):
if citables: if citables:
Citable.objects.insert(citables) Citable.objects.insert(citables)
break break
else: elif errors:
print("Trying again") print("Trying again")
else:
break
citable = [] citable = []
...@@ -118,3 +122,4 @@ def parse_crossref_citable(citable_item): ...@@ -118,3 +122,4 @@ def parse_crossref_citable(citable_item):
except Exception as e: except Exception as e:
print("Error: ", e) print("Error: ", e)
print(citable_item['DOI']) print(citable_item['DOI'])
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment