From 65f9e26fb8e8088c1a559eeebb7b87dc51a86115 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Wed, 1 Aug 2018 02:04:48 +0200 Subject: [PATCH] steam: decrease the number of dependencies by using difflib from Python standard library instead of fuzzywuzzy. --- README.md | 2 -- dailyreleases/steam.py | 15 +++++++-------- setup.py | 3 +-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a05c0b5..2901c24 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ pip3 install --upgrade https://git.caspervk.net/caspervk/dailyreleases/archive/m **It requires Python 3.6 or later.** -To speed up fuzzy string matching, it may be desirable to install `python3-levenshtein`. - ### Usage The program can be started by running `dailyreleases` or `python3 -m dailyreleases` depending on system configuration. diff --git a/dailyreleases/steam.py b/dailyreleases/steam.py index ed46430..adc0ac7 100644 --- a/dailyreleases/steam.py +++ b/dailyreleases/steam.py @@ -1,7 +1,6 @@ +import difflib import logging -from fuzzywuzzy import process, fuzz - logger = logging.getLogger(__name__) @@ -54,16 +53,16 @@ class Steam(object): } results = self.cache.get("https://store.steampowered.com/api/storesearch", params=payload).json()["items"] - best_match = process.extractOne(query, - [r["name"] for r in results], - scorer=fuzz.ratio, # could also use 'fuzz.token_sort_ratio'? - score_cutoff=90) + best_match = difflib.get_close_matches(query, + [r["name"] for r in results], + n=1, + cutoff=0.90) if not best_match: logger.debug("Unable to find %s in Steam search results", query) return - logger.debug("Best match is '%s' with score %s", *best_match) - return next(f"https://store.steampowered.com/{r['type']}/{r['id']}" + logger.debug("Best match is '%s'", best_match[0]) + return next("https://store.steampowered.com/{}/{}".format(r["type"], r["id"]) for r in results if r["name"] == best_match[0]) diff --git a/setup.py b/setup.py index 03c554f..c97a0e6 100644 --- a/setup.py +++ b/setup.py @@ -41,8 +41,7 @@ setup( "requests_cache", "praw", "beautifulsoup4", - "tabulate", - "fuzzywuzzy" + "tabulate" ], entry_points={ "console_scripts": [