feat: add manual HLTB matching
Allow setting an HLTB ID for missed games via POST /api/hltb/match and a small modal on the HLTB page.
This commit is contained in:
1 parent
92c4c62ca9
commit
6644a94d8c
5 files changed
+169
-2
No files matched your search
@@ -40,6 +40,7 @@ for stream in (sys.stdout, sys.stderr):
|
||||
import check_updates
|
||||
import covers
|
||||
import db
|
||||
import fetch_hltb
|
||||
import reco
|
||||
import steam_api
|
||||
import steam_source
|
||||
@@ -821,6 +822,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._json({"started": JOBS.retry()})
|
||||
elif path == "/api/hltb":
|
||||
self._start_hltb(self._body())
|
||||
elif path == "/api/hltb/match":
|
||||
self._hltb_match(self._body())
|
||||
elif path == "/api/refresh":
|
||||
body = self._body()
|
||||
mode = body.get("mode", "incremental")
|
||||
@@ -1957,6 +1960,62 @@ class Handler(BaseHTTPRequestHandler):
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def _hltb_match(self, body):
|
||||
if importlib.util.find_spec("howlongtobeatpy") is None:
|
||||
self._error(400, "howlongtobeatpy не установлен: pip install -r requirements-hltb.txt")
|
||||
return
|
||||
try:
|
||||
appid = int(body.get("appid"))
|
||||
except (TypeError, ValueError):
|
||||
self._error(400, "invalid appid")
|
||||
return
|
||||
try:
|
||||
hltb_id = int(body.get("hltb_id"))
|
||||
except (TypeError, ValueError):
|
||||
self._error(400, "invalid HLTB id")
|
||||
return
|
||||
if hltb_id <= 0:
|
||||
self._error(400, "invalid HLTB id")
|
||||
return
|
||||
try:
|
||||
entry = fetch_hltb.HowLongToBeat().search_from_id(hltb_id)
|
||||
except Exception as exc:
|
||||
self._error(502, f"HLTB: {exc}")
|
||||
return
|
||||
if not entry:
|
||||
self._error(404, "HLTB game not found")
|
||||
return
|
||||
main_hours = fetch_hltb.positive(getattr(entry, "main_story", None))
|
||||
extra_hours = fetch_hltb.positive(getattr(entry, "main_extra", None))
|
||||
complete_hours = fetch_hltb.positive(getattr(entry, "completionist", None))
|
||||
best = main_hours or extra_hours or complete_hours
|
||||
if not best:
|
||||
self._error(422, "no playtime for this HLTB game")
|
||||
return
|
||||
|
||||
con = connect()
|
||||
try:
|
||||
exists = con.execute("SELECT 1 FROM games WHERE appid = ?", (appid,)).fetchone()
|
||||
if not exists:
|
||||
self._error(404, "unknown appid")
|
||||
return
|
||||
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
con.execute(
|
||||
"""UPDATE games SET hltb_main = ?, hltb_extra = ?, hltb_complete = ?,
|
||||
hltb_id = ?, hltb_checked_at = ?, hltb_match = 1,
|
||||
hltb_updated_at = ?, estimated_hours = ?
|
||||
WHERE appid = ?""",
|
||||
(main_hours, extra_hours, complete_hours, hltb_id, now, now,
|
||||
best, appid))
|
||||
con.commit()
|
||||
self._json({
|
||||
"appid": appid, "hltb_id": hltb_id,
|
||||
"main": main_hours, "extra": extra_hours, "complete": complete_hours,
|
||||
"estimated_hours": best,
|
||||
})
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def _start_hltb(self, body):
|
||||
if importlib.util.find_spec("howlongtobeatpy") is None:
|
||||
self._error(400, "howlongtobeatpy не установлен: pip install -r requirements-hltb.txt")
|
||||
|
||||
Reference in new issue
Block a user