Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement querying of the correct registration authority #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/sphinx_tippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,28 @@ def fetch_doi_tips(app: Sphinx, data: dict[str, TippyPageData]) -> dict[str, str
doi for page in data.values() for doi in page["dois"] if doi not in doi_cache
}
for doi in status_iterator(doi_fetch, "Fetching DOI tips", length=len(doi_fetch)):
url = f"{config.doi_api}{doi}"
# Resolve the RA from doi.org
url = (
"https://doi.org/api/handles/"
+ doi.replace("https://doi.org/", "").split("/")[0]
)
api_url = config.doi_api
try:
authority = requests.get(url).json()["values"][0]["data"]["value"]
if authority == "10.SERV/DATACITE":
api_url = "https://api.datacite.org/dois/"
elif authority == "10.SERV/CROSSREF":
api_url = "https://api.crossref.org/works/"
else:
raise ValueError(f"Unknown DOI authority: {authority}")
except Exception as exc:
LOGGER.warning(
f"Could not fetch DOI authority for {doi}: {exc} [tippy.doi]",
type="tippy",
subtype="doi",
)
continue
url = f"{api_url}{doi}"
try:
data = requests.get(url).json()
except Exception as exc:
Expand Down