Skip to content

Instantly share code, notes, and snippets.

@J535D165
Created August 10, 2022 12:30
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 J535D165/fe976eddb871cf3ef84c016f723ddd82 to your computer and use it in GitHub Desktop.
Save J535D165/fe976eddb871cf3ef84c016f723ddd82 to your computer and use it in GitHub Desktop.
Resolve the URL of the DOI
import requests
def get_url_from_doi(doi):
"""Get the url from the DOI.
Arguments
---------
doi: str
The DOI to find the url for.
Returns
-------
str:
The url.
"""
r = requests.head(f"https://doi.org/{doi}", allow_redirects=True)
return r.url
def test_url_retrieval():
assert get_url_from_doi("10.34894/KEIQRD") == "https://dataverse.nl/dataset.xhtml?persistentId=doi:10.34894/KEIQRD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment