Skip to content

Instantly share code, notes, and snippets.

@kagaya
Created December 4, 2024 11:10
Show Gist options
  • Save kagaya/acda697bffdccff8b22ab7a517878dba to your computer and use it in GitHub Desktop.
Save kagaya/acda697bffdccff8b22ab7a517878dba to your computer and use it in GitHub Desktop.
doi to bibtex
#!/usr/bin/env python3
import sys
import requests
def get_bibtex(doi):
url = f"https://doi.org/{doi}"
headers = {"Accept": "application/x-bibtex"}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.text
except requests.exceptions.RequestException as e:
return f"Error: {e}"
def main():
if len(sys.argv) != 2:
print("Usage: doi2bibtex <DOI>")
sys.exit(1)
doi = sys.argv[1]
bibtex = get_bibtex(doi)
print(bibtex)
if __name__ == "__main__":
main()
@kagaya
Copy link
Author

kagaya commented Dec 4, 2024

pip install requests
chmod +x doi2bibtex.py

@kagaya
Copy link
Author

kagaya commented Dec 4, 2024

example

python doi2bibtex.py 10.1523/JNEUROSCI.4885-09.2010
@Article{Kagaya_2010, title={Readiness Discharge for Spontaneous Initiation of Walking in Crayfish}, volume={30}, ISSN={1529-2401}, url={http://dx.doi.org/10.1523/JNEUROSCI.4885-09.2010}, DOI={10.1523/jneurosci.4885-09.2010}, number={4}, journal={The Journal of Neuroscience}, publisher={Society for Neuroscience}, author={Kagaya, Katsushi and Takahata, Masakazu}, year={2010}, month=jan, pages={1348–1362} }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment