Skip to content

Instantly share code, notes, and snippets.

@jonaprieto
Last active April 10, 2023 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonaprieto/5dc111485afb7cfb34e86796f35d5a0b to your computer and use it in GitHub Desktop.
Save jonaprieto/5dc111485afb7cfb34e86796f35d5a0b to your computer and use it in GitHub Desktop.
Print which dois are broken
import requests
import pybtex.database
with open('./ref.bib') as bibfile:
bib_database = pybtex.database.parse_file(bibfile)
for key in bib_database.entries.keys():
entry = bib_database.entries[key]
if 'doi' in entry.fields:
doi = entry.fields['doi'].replace('\_', '_')
url = f'https://dx.doi.org/{doi}'
response1 = requests.get(url)
if response1.status_code != 200:
alt_url = f'https://doi.org/{doi}'
response2 = requests.get(alt_url)
if response2.status_code != 200:
if 'JSTOR' in response1.text or 'JSTOR' in response2.text:
print(f'{doi} is broken, but JSTOR maybe the reason')
else:
print(f'{doi} is broken')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment