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.**
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.

View file

@ -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])

View file

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