Add fuzzing for book titles

This commit is contained in:
2024-01-27 00:20:15 -05:00
parent 0b3bc53704
commit 919fa1b0b4
5 changed files with 248 additions and 590 deletions

View File

@ -5,6 +5,8 @@ import urllib
import requests
from thefuzz import fuzz
logger = logging.getLogger(__name__)
ISBN_URL = "https://openlibrary.org/isbn/{isbn}.json"
@ -102,8 +104,9 @@ def lookup_book_from_openlibrary(
top = None
for result in results.get("docs"):
if title.lower() == result.get("title", "").lower():
if fuzz.ratio(title.lower(), result.get("title", "").lower()) > 90:
top = result
break
if not top:
for result in results.get("docs"):