Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 3rd-party thefuzz with stdlib difflib.get_close_matches #168

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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
Loading