commit 2f53b6f85be07a47e6dc1033a2d8d5b7991d0d5e parent a56375a9b16377c7ef713b82cd0725e3f026b825 Author: Anders Damsgaard Christensen <adc@geo.au.dk> Date: Thu, 12 Jan 2017 13:14:18 -0800 add error handling for doi search service Diffstat:
M | bin/scholarref.py | | | 13 | ++++++++++--- |
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/bin/scholarref.py b/bin/scholarref.py @@ -39,11 +39,18 @@ nhits = 1 # Use crossref metadata search (beta) to get the DOI params = {'q': query, 'rows': str(nhits)} -r = requests.get('http://search.labs.crossref.org/dois', params=params) +doi_search_url = 'http://search.labs.crossref.org/dois' +r = requests.get(doi_search_url, params=params) dois = [] -for j in r.json(): - dois.append(j['doi'].split('dx.doi.org/')[1]) +try: + for j in r.json(): + dois.append(j['doi'].split('dx.doi.org/')[1]) +except Exception as e: + print('Error: ' + str(e)) + print('Maybe DOI service at ' + doi_search_url + ' is unavailable?') + print('Server response: ' + str(r)) + sys.exit(1) # get the DOI of the first result doi = dois[0]