Check based on doi
tdegeus opened this issue · 0 comments
tdegeus commented
The following code can be used to obtain a BibTeX file from a doi
import sys
import urllib.request
from urllib.error import HTTPError
BASE_URL = 'http://dx.doi.org/'
doi = '10.1073/pnas.1906551116'
url = BASE_URL + doi
req = urllib.request.Request(url)
req.add_header('Accept', 'application/x-bibtex')
try:
with urllib.request.urlopen(req) as f:
bibtex = f.read().decode()
print(bibtex)
except HTTPError as e:
if e.code == 404:
print('DOI not found.')
else:
print('Service unavailable.')
sys.exit(1)
This could be optimised to check a BibTeX file