1
0
Fork 0

steam: decrease the number of dependencies by using difflib from Python standard library instead of fuzzywuzzy.

This commit is contained in:
Casper V. Kristensen 2018-08-01 02:04:48 +02:00
parent 2915c5c31e
commit 65f9e26fb8
Signed by: caspervk
GPG key ID: B1156723DB3BDDA8
3 changed files with 8 additions and 12 deletions

View file

@ -10,8 +10,6 @@ pip3 install --upgrade https://git.caspervk.net/caspervk/dailyreleases/archive/m
**It requires Python 3.6 or later.** **It requires Python 3.6 or later.**
To speed up fuzzy string matching, it may be desirable to install `python3-levenshtein`.
### Usage ### Usage
The program can be started by running `dailyreleases` or `python3 -m dailyreleases` depending on system configuration. The program can be started by running `dailyreleases` or `python3 -m dailyreleases` depending on system configuration.

View file

@ -1,7 +1,6 @@
import difflib
import logging import logging
from fuzzywuzzy import process, fuzz
logger = logging.getLogger(__name__) 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"] results = self.cache.get("https://store.steampowered.com/api/storesearch", params=payload).json()["items"]
best_match = process.extractOne(query, best_match = difflib.get_close_matches(query,
[r["name"] for r in results], [r["name"] for r in results],
scorer=fuzz.ratio, # could also use 'fuzz.token_sort_ratio'? n=1,
score_cutoff=90) cutoff=0.90)
if not best_match: if not best_match:
logger.debug("Unable to find %s in Steam search results", query) logger.debug("Unable to find %s in Steam search results", query)
return return
logger.debug("Best match is '%s' with score %s", *best_match) logger.debug("Best match is '%s'", best_match[0])
return next(f"https://store.steampowered.com/{r['type']}/{r['id']}" return next("https://store.steampowered.com/{}/{}".format(r["type"], r["id"])
for r in results for r in results
if r["name"] == best_match[0]) if r["name"] == best_match[0])

View file

@ -41,8 +41,7 @@ setup(
"requests_cache", "requests_cache",
"praw", "praw",
"beautifulsoup4", "beautifulsoup4",
"tabulate", "tabulate"
"fuzzywuzzy"
], ],
entry_points={ entry_points={
"console_scripts": [ "console_scripts": [