This commit is contained in:
1 parent
2f39ee11df
commit
da30de0318
16 files changed
+142
-22
No files matched your search
+8
-1
@@ -8,7 +8,7 @@ from datetime import datetime, timezone
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
DEFAULT_DB = os.path.join(BASE_DIR, "steam.db")
|
||||
SCHEMA_PATH = os.path.join(BASE_DIR, "tools", "schema.sql")
|
||||
SCHEMA_VERSION = 6
|
||||
SCHEMA_VERSION = 7
|
||||
|
||||
MOOD_PRESETS = {
|
||||
"adventure-rpg-party": {
|
||||
@@ -562,6 +562,12 @@ def _migration_6(con):
|
||||
_ensure_column(con, "games", column, declaration)
|
||||
|
||||
|
||||
def _migration_7(con):
|
||||
"""Track HLTB checks (including games without a match)."""
|
||||
_ensure_column(con, "games", "hltb_checked_at", "TEXT")
|
||||
_ensure_column(con, "games", "hltb_match", "INTEGER")
|
||||
|
||||
|
||||
MIGRATIONS = {
|
||||
1: _migration_1,
|
||||
2: _migration_2,
|
||||
@@ -569,6 +575,7 @@ MIGRATIONS = {
|
||||
4: _migration_4,
|
||||
5: _migration_5,
|
||||
6: _migration_6,
|
||||
7: _migration_7,
|
||||
}
|
||||
|
||||
|
||||
|
||||
+24
-5
@@ -62,7 +62,9 @@ def main():
|
||||
ap.add_argument("--db", default=db.DEFAULT_DB)
|
||||
ap.add_argument("--limit", type=int, default=100)
|
||||
ap.add_argument("--all", action="store_true")
|
||||
ap.add_argument("--refresh", action="store_true", help="refetch games already enriched")
|
||||
ap.add_argument("--refresh", action="store_true", help="refetch all games")
|
||||
ap.add_argument("--retry-missed", action="store_true",
|
||||
help="retry games that were checked without a match")
|
||||
ap.add_argument("--delay", type=float, default=0.5)
|
||||
ap.add_argument("--dry-run", action="store_true")
|
||||
args = ap.parse_args()
|
||||
@@ -76,7 +78,10 @@ def main():
|
||||
db.init(con)
|
||||
where = ["LOWER(type) = 'game'"]
|
||||
if not args.refresh:
|
||||
where.append("hltb_updated_at IS NULL")
|
||||
if args.retry_missed:
|
||||
where.append("(hltb_checked_at IS NULL OR hltb_match = 0)")
|
||||
else:
|
||||
where.append("hltb_checked_at IS NULL")
|
||||
sql = (f"SELECT appid, name FROM games WHERE {' AND '.join(where)} "
|
||||
"ORDER BY COALESCE(review_pct, 0) DESC, name")
|
||||
rows = con.execute(sql).fetchall()
|
||||
@@ -97,6 +102,13 @@ def main():
|
||||
entry = find_match(entries, row["name"])
|
||||
if not entry:
|
||||
missing += 1
|
||||
if not args.dry_run:
|
||||
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
con.execute(
|
||||
"""UPDATE games SET hltb_checked_at = ?,
|
||||
hltb_match = CASE WHEN hltb_id IS NOT NULL THEN 1 ELSE 0 END
|
||||
WHERE appid = ?""", (now, row["appid"]))
|
||||
con.commit()
|
||||
time.sleep(args.delay)
|
||||
if index % 20 == 0 or index == len(rows):
|
||||
print(f" {index}/{len(rows)} matched={matched} missing={missing} errors={errors}")
|
||||
@@ -106,19 +118,26 @@ def main():
|
||||
extra_hours = positive(getattr(entry, "main_extra", None))
|
||||
complete_hours = positive(getattr(entry, "completionist", None))
|
||||
best = main_hours or extra_hours or complete_hours
|
||||
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
if not best:
|
||||
missing += 1
|
||||
if not args.dry_run:
|
||||
con.execute(
|
||||
"""UPDATE games SET hltb_checked_at = ?,
|
||||
hltb_match = CASE WHEN hltb_id IS NOT NULL THEN 1 ELSE 0 END
|
||||
WHERE appid = ?""", (now, row["appid"]))
|
||||
con.commit()
|
||||
time.sleep(args.delay)
|
||||
continue
|
||||
matched += 1
|
||||
if not args.dry_run:
|
||||
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
con.execute(
|
||||
"""UPDATE games SET hltb_main = ?, hltb_extra = ?, hltb_complete = ?,
|
||||
hltb_id = ?, hltb_updated_at = ?, estimated_hours = ?
|
||||
hltb_id = ?, hltb_checked_at = ?, hltb_match = 1,
|
||||
hltb_updated_at = ?, estimated_hours = ?
|
||||
WHERE appid = ?""",
|
||||
(main_hours, extra_hours, complete_hours,
|
||||
getattr(entry, "game_id", None), now, best, row["appid"]))
|
||||
getattr(entry, "game_id", None), now, now, best, row["appid"]))
|
||||
con.commit()
|
||||
if index % 10 == 0 or index == len(rows):
|
||||
print(f" {index}/{len(rows)} matched={matched} missing={missing} errors={errors}")
|
||||
|
||||
@@ -18,6 +18,8 @@ CREATE TABLE IF NOT EXISTS games (
|
||||
hltb_extra REAL,
|
||||
hltb_complete REAL,
|
||||
hltb_id INTEGER,
|
||||
hltb_checked_at TEXT,
|
||||
hltb_match INTEGER,
|
||||
hltb_updated_at TEXT,
|
||||
updated_at TEXT
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user