Skip to content

Commit

Permalink
Replace 3rd-party thefuzz with stdlib difflib.get_close_matches
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jul 29, 2023
1 parent 0775764 commit 913468c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ dependencies = [
"python-dateutil",
"python-slugify",
"termcolor>=2.1",
"thefuzz",
]
[project.optional-dependencies]
tests = [
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ pytest-cov==4.1.0
python-slugify==8.0.1
respx==0.20.1
termcolor==2.3.0
thefuzz==0.19.0
8 changes: 2 additions & 6 deletions src/norwegianblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,13 @@ def norwegianblue(

@lru_cache(maxsize=None)
def suggest_product(product: str) -> str:
import warnings

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
from thefuzz import process
import difflib

# Get all known products from the API or cache
all_products = norwegianblue("all").splitlines()

# Find the closest match
result = process.extractOne(product, all_products)
result = difflib.get_close_matches(product, all_products, n=1)
logging.info("Suggestion:\t%s (score: %d)", *result)
return result[0]

Expand Down

0 comments on commit 913468c

Please sign in to comment.