Skip to content

Commit

Permalink
manubot#337 Add timeout to wikidata.
Browse files Browse the repository at this point in the history
wikidata -[depends]-> url
  • Loading branch information
xihh87 committed Jul 28, 2022
1 parent a261f30 commit 226884a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions manubot/cite/wikidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .handlers import Handler

default_timeout = 3


class Handler_Wikidata(Handler):
prefixes = ["wikidata"]
Expand All @@ -21,11 +23,15 @@ def inspect(self, citekey):
"Double check the entity ID."
)

def get_csl_item(self, citekey):
return get_wikidata_csl_item(citekey.standard_accession)
def get_csl_item(self, citekey, timeout_seconds: int = default_timeout):
return get_wikidata_csl_item(
citekey.standard_accession, timeout_seconds=timeout_seconds
)


def get_wikidata_csl_item(identifier: str) -> Dict[str, Any]:
def get_wikidata_csl_item(
identifier: str, timeout_seconds: int = default_timeout
) -> Dict[str, Any]:
"""
Get a CSL JSON item with the citation metadata for a Wikidata item.
identifier should be a Wikidata item ID corresponding to a citeable
Expand All @@ -34,7 +40,7 @@ def get_wikidata_csl_item(identifier: str) -> Dict[str, Any]:
url = f"https://www.wikidata.org/wiki/{identifier}"
from manubot.cite.url import get_url_csl_item_zotero

csl_item = get_url_csl_item_zotero(url)
csl_item = get_url_csl_item_zotero(url, timeout_seconds=timeout_seconds)
if "DOI" in csl_item:
csl_item["DOI"] = csl_item["DOI"].lower()
if "URL" not in csl_item:
Expand Down

0 comments on commit 226884a

Please sign in to comment.