1
0
Fork 0

normalise isbn on local book search

- uppercase ISBN before checking it's a number to account for trailing 'x'
- check maybe_isbn for search_identifiers search. Without this we are only searching external connectors, not locally!
This commit is contained in:
Hugh Rundle 2022-08-30 20:00:09 +10:00
parent 68d91086ed
commit 1ee2ff4811
3 changed files with 8 additions and 3 deletions

View file

@ -1,6 +1,6 @@
""" bring connectors into the namespace """
from .settings import CONNECTORS
from .abstract_connector import ConnectorException
from .abstract_connector import get_data, get_image
from .abstract_connector import get_data, get_image, maybe_isbn
from .connector_manager import search, first_search_result

View file

@ -328,10 +328,10 @@ def maybe_isbn(query):
"""check if a query looks like an isbn"""
isbn = re.sub(r"[\W_]", "", query) # removes filler characters
# ISBNs must be numeric except an ISBN10 checkdigit can be 'X'
if not isbn.rstrip("X").isnumeric():
if not isbn.upper().rstrip("X").isnumeric():
return False
return len(isbn) in [
9,
10,
13,
] # ISBN10 or ISBN13, or maybe ISBN10 missing a prepended zero
] # ISBN10 or ISBN13, or maybe ISBN10 missing a leading zero