Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
micsutil: prevent CrossRef request HTTPError
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Gaudencio <[email protected]>
  • Loading branch information
pedrogaudencio committed Mar 24, 2015
1 parent df7c4f0 commit a7d4862
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions modules/miscutil/lib/crossrefutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,23 @@ def get_metadata_for_dois(dois):
url = "http://doi.crossref.org/servlet/query"
data = urllib.urlencode(params)

for line in CROSSREF_OPENER.open(url, data):
line = line.split("|")
if len(line) == 1:
pass
elif len(line) in (10, 12):
is_book = len(line) == 12
if is_book:
record_data = dict(zip(FIELDS_BOOK, line))
try:
for line in CROSSREF_OPENER.open(url, data):
line = line.split("|")
if len(line) == 1:
pass
elif len(line) in (10, 12):
is_book = len(line) == 12
if is_book:
record_data = dict(zip(FIELDS_BOOK, line))
else:
record_data = dict(zip(FIELDS_JOURNAL, line))
record_data["is_book"] = is_book
metadata[record_data["doi"]] = record_data
else:
record_data = dict(zip(FIELDS_JOURNAL, line))
record_data["is_book"] = is_book
metadata[record_data["doi"]] = record_data
else:
raise CrossrefError("Crossref response not understood")
raise CrossrefError("Crossref response not understood")
except urllib2.HTTPError:
raise CrossrefError("Crossref response not understood")

return metadata

Expand Down

0 comments on commit a7d4862

Please sign in to comment.