steam: decrease the number of dependencies by using difflib from Python standard library instead of fuzzywuzzy.
This commit is contained in:
parent
2915c5c31e
commit
65f9e26fb8
|
@ -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.
|
||||
|
||||
|
|
|
@ -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,
|
||||
best_match = difflib.get_close_matches(query,
|
||||
[r["name"] for r in results],
|
||||
scorer=fuzz.ratio, # could also use 'fuzz.token_sort_ratio'?
|
||||
score_cutoff=90)
|
||||
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])
|
||||
|
|
Reference in a new issue