Skip to content

Instantly share code, notes, and snippets.

@edsu
Last active January 10, 2024 17:54
Show Gist options
  • Save edsu/2822734f747f7b3d7c5776dc33efd47b to your computer and use it in GitHub Desktop.
Save edsu/2822734f747f7b3d7c5776dc33efd47b to your computer and use it in GitHub Desktop.
Use the CrossRef API to guess the DOI for a given title
#!/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