Files
SteamBase/tools/recommend.py
T
strsv 2f5791d1a3 feat: exclude completed games from recommendations
Skip played and ignore statuses by default; add an include-played toggle to the API, CLI and UI for replay suggestions.
2026-11-07 00:57:53 +03:00

108 lines
4.1 KiB
Python

"""Mood-based recommendations from steam.db.
Examples:
python tools/recommend.py --mood "рпг приключение прокачка группы исследование подземелья"
python tools/recommend.py --preset adventure-rpg-party --unplayed-only
python tools/recommend.py --list-presets
"""
import argparse
import json
import os
import sys
for stream in (sys.stdout, sys.stderr):
try:
stream.reconfigure(encoding="utf-8")
except Exception:
pass
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import db
import reco
def main():
ap = argparse.ArgumentParser(description="Recommend games for a mood")
ap.add_argument("--mood", help="free text, Russian or English")
ap.add_argument("--preset", help="mood preset name")
ap.add_argument("--list-presets", action="store_true")
ap.add_argument("--limit", type=int, default=20)
ap.add_argument("--min-review", type=int, default=65,
help="skip games below this Steam review percentage (default 65)")
ap.add_argument("--db", default=db.DEFAULT_DB)
ap.add_argument("--unplayed-only", action="store_true", help="only games with 0 minutes")
ap.add_argument("--include-played", action="store_true",
help="include games marked as completed (status=played)")
ap.add_argument("--include-tribute", action="store_true",
help="include games you played outside Steam (status=tribute)")
ap.add_argument("--include-nostalgia", action="store_true",
help="include games kept unplayed on purpose (status=nostalgia)")
ap.add_argument("--allow-unknown", action="store_true",
help="also consider games without any review/metacritic score")
ap.add_argument("--taste", choices=sorted(reco.TASTE_PROFILES),
help="play-context taste profile (solo/coop)")
ap.add_argument("--json", action="store_true")
args = ap.parse_args()
con = db.connect(args.db)
db.init(con)
db.seed_moods(con)
if args.list_presets:
for row in con.execute("SELECT name, description FROM moods ORDER BY name"):
print(f"{row['name']:22} {row['description']}")
return
try:
mood = reco.load_mood(con, args.preset, args.mood)
except KeyError as exc:
raise SystemExit(f"Unknown preset: {exc.args[0]}")
except ValueError:
raise SystemExit('Pass --mood "..." or --preset NAME (see --list-presets)')
if not mood["tags"] and not mood["genres"]:
raise SystemExit("Could not understand the mood; try different words")
allowed = {"backlog", "playing"}
if args.include_played:
allowed.add("played")
if args.include_tribute:
allowed.add("tribute")
if args.include_nostalgia:
allowed.add("nostalgia")
mood, results = reco.recommend(
con, mood, allowed_statuses=allowed, unplayed_only=args.unplayed_only,
min_review=args.min_review, allow_unknown=args.allow_unknown, limit=args.limit,
taste_profile=args.taste,
)
if args.json:
print(json.dumps({"mood": mood, "results": results}, ensure_ascii=False, indent=2))
return
print(f"Настроение: {mood['description']}")
print(f"Теги: {', '.join(mood['tags'])}")
if mood["genres"]:
print(f"Жанры: {', '.join(sorted(mood['genres']))}")
print()
for i, g in enumerate(results, 1):
flags = ["установлена" if g["installed"] else None,
f"{g['hours']:g} ч" if g["hours"] else "не запускалась",
g["status"] if g["status"] != "backlog" else None]
flags = [f for f in flags if f]
q = []
if g["review"] is not None:
q.append(f"{g['review']}%")
if g["metacritic"] is not None:
q.append(f"MC {g['metacritic']}")
print(f"{i:2}. {g['name']} [{g['score']}]")
print(f" совпало: {', '.join(g['matched']) or '-'}")
print(f" {' · '.join(flags)}" + (f" · {', '.join(q)}" if q else ""))
if __name__ == "__main__":
main()