fix: backfill release years from store dates
CI / test (push) Successful in 4m43s

This commit is contained in:
strsv committed 2026-11-06 20:34:19 +03:00
1 parent db3e6e4f94
commit 2828ec48c8
10 files changed
+124 -11

No files matched your search

+71 -1
View File
@@ -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 = 4
SCHEMA_VERSION = 5
MOOD_PRESETS = {
"adventure-rpg-party": {
@@ -375,6 +375,70 @@ def estimate_hours(genres, tag_names):
return round(max(2.0, min(100.0, hours)), 1)
MONTHS = {
"янв": 1, "фев": 2, "мар": 3, "апр": 4, "май": 5, "мая": 5, "июн": 6,
"июл": 7, "авг": 8, "сен": 9, "сент": 9, "окт": 10, "ноя": 11, "дек": 12,
"jan": 1, "feb": 2, "mar": 3, "apr": 4, "may": 5, "jun": 6,
"jul": 7, "aug": 8, "sep": 9, "sept": 9, "oct": 10, "nov": 11, "dec": 12,
}
def parse_release_date(value):
"""Parse common Steam store dates into YYYY-MM-DD or YYYY."""
text = " ".join(str(value or "").lower().replace("\xa0", " ").split())
if not text:
return None
year = re.search(r"\b(19|20)\d{2}\b", text)
if not year:
return None
year_value = int(year.group(0))
day_month = re.search(r"\b(\d{1,2})\s+([a-zа-яё]+)\.?", text)
if day_month:
month = MONTHS.get(day_month.group(2)[:4])
if month:
day = int(day_month.group(1))
if 1 <= day <= 31:
return f"{year_value:04d}-{month:02d}-{day:02d}"
month_day = re.search(r"\b([a-zа-яё]+)\.?\s+(\d{1,2}),?", text)
if month_day:
month = MONTHS.get(month_day.group(1)[:4])
if month:
day = int(month_day.group(2))
if 1 <= day <= 31:
return f"{year_value:04d}-{month:02d}-{day:02d}"
return f"{year_value:04d}"
def update_game_release(con, appid, value):
parsed = parse_release_date(value)
if not parsed:
return False
con.execute(
"""UPDATE games SET release_date = ?
WHERE appid = ? AND COALESCE(release_date, '') = ''""", (parsed, appid))
return True
def backfill_release_dates(con):
"""Fill missing games.release_date from localized Store dates."""
rows = con.execute("""
SELECT g.appid, d.release_date
FROM games g JOIN game_details d ON d.appid = g.appid
WHERE LOWER(g.type) = 'game'
AND COALESCE(g.release_date, '') = ''
AND COALESCE(d.release_date, '') <> ''
""").fetchall()
updates = []
for row in rows:
parsed = parse_release_date(row["release_date"])
if parsed:
updates.append((parsed, row["appid"]))
if updates:
con.executemany("UPDATE games SET release_date = ? WHERE appid = ?", updates)
con.commit()
return len(updates)
def refresh_duration_estimates(con):
"""Recompute games.estimated_hours for all games."""
genres = {}
@@ -413,11 +477,17 @@ def _migration_4(con):
refresh_duration_estimates(con)
def _migration_5(con):
"""Backfill release years from localized Store dates."""
backfill_release_dates(con)
MIGRATIONS = {
1: _migration_1,
2: _migration_2,
3: _migration_3,
4: _migration_4,
5: _migration_5,
}