Last active
January 10, 2024 17:54
-
-
Save edsu/2822734f747f7b3d7c5776dc33efd47b to your computer and use it in GitHub Desktop.
Use the CrossRef API to guess the DOI for a given title
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
#!/usr/bin/env python3 | |
import sys | |
import requests | |
title = sys.argv[1] | |
api_url = "https://api.crossref.org/works" | |
response = requests.get(api_url, params={"query.title": title}) | |
if response.status_code != 200: | |
exit("uhoh, got a bad response from Crossref: {response}") | |
for item in response.json()['message']['items']: | |
print(item['DOI']) | |
print(item['title'][0]) | |
for author in item.get('author', []): | |
print('-', author['given'], author['family']) | |
print() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment