Skip to content

Commit

Permalink
manubot#337 tag all timeout args in isbn.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jun 15, 2022
1 parent ff6f901 commit c8177e6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions manubot/cite/isbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Handler_ISBN(Handler):
"isbn",
]

def inspect(self, citekey, timeout=3):
def inspect(self, citekey, timeout: int = 3):
import isbnlib

isbnlib.config.setthreadstimeout(seconds=timeout)
isbnlib.config.seturlopentimeout(seconds=timeout)

Expand All @@ -28,11 +29,11 @@ def standardize_prefix_accession(self, accession):
accession = to_isbn13(accession)
return self.standard_prefix, accession

def get_csl_item(self, citekey):
return get_isbn_csl_item(citekey.standard_accession)
def get_csl_item(self, citekey, timeout: int = 3):
return get_isbn_csl_item(citekey.standard_accession, timeout=timeout)


def get_isbn_csl_item(isbn: str, timeout=3):
def get_isbn_csl_item(isbn: str, timeout: int = 3):
"""
Generate CSL JSON Data for an ISBN. Converts all ISBNs to 13-digit format.
Expand All @@ -42,6 +43,7 @@ def get_isbn_csl_item(isbn: str, timeout=3):
non-failing method.
"""
import isbnlib

isbnlib.config.setthreadstimeout(seconds=timeout)
isbnlib.config.seturlopentimeout(seconds=timeout)

Expand All @@ -58,16 +60,16 @@ def get_isbn_csl_item(isbn: str, timeout=3):
raise Exception(f"all get_isbn_csl_item methods failed for {isbn}")


def get_isbn_csl_item_zotero(isbn: str):
def get_isbn_csl_item_zotero(isbn: str, timeout: int = 3):
"""
Generate CSL JSON Data for an ISBN using Zotero's translation-server.
"""
from manubot.cite.zotero import get_csl_item

return get_csl_item(f"isbn:{isbn}")
return get_csl_item(f"isbn:{isbn}", timeout=timeout)


def get_isbn_csl_item_citoid(isbn: str, timeout=3):
def get_isbn_csl_item_citoid(isbn: str, timeout: int = 3):
"""
Return CSL JSON Data for an ISBN using the Wikipedia Citoid API.
https://en.wikipedia.org/api/rest_v1/#!/Citation/getCitation
Expand All @@ -78,7 +80,7 @@ def get_isbn_csl_item_citoid(isbn: str, timeout=3):

headers = {"User-Agent": get_manubot_user_agent()}
url = f"https://en.wikipedia.org/api/rest_v1/data/citation/mediawiki/{isbn}"
response = requests.get(url, headers=headers, timeout=timeut)
response = requests.get(url, headers=headers, timeout=timeout)
result = response.json()
if isinstance(result, dict):
if result["title"] == "Not found.":
Expand Down Expand Up @@ -129,11 +131,12 @@ def get_isbn_csl_item_citoid(isbn: str, timeout=3):
return csl_item


def get_isbn_csl_item_isbnlib(isbn: str, timeout=3):
def get_isbn_csl_item_isbnlib(isbn: str, timeout: int = 3):
"""
Generate CSL JSON Data for an ISBN using isbnlib.
"""
import isbnlib

isbnlib.config.setthreadstimeout(seconds=timeout)
isbnlib.config.seturlopentimeout(seconds=timeout)

Expand Down

0 comments on commit c8177e6

Please sign in to comment.