Last active
April 10, 2023 21:08
-
-
Save jonaprieto/5dc111485afb7cfb34e86796f35d5a0b to your computer and use it in GitHub Desktop.
Print which dois are broken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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