50
homelab/scripts/merge_names_into_sizes.py
Normal file
50
homelab/scripts/merge_names_into_sizes.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Однократно подтягивает названия игр из steam_library.json в steam_library_with_sizes.json.
|
||||
Размеры берутся из кэша steam_app_sizes.json. Запускать из homelab/scripts/.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPT_DIR = Path(__file__).parent
|
||||
LIBRARY_FILE = SCRIPT_DIR / "steam_library.json"
|
||||
CACHE_FILE = SCRIPT_DIR / "steam_app_sizes.json"
|
||||
OUTPUT_FILE = SCRIPT_DIR / "steam_library_with_sizes.json"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if not LIBRARY_FILE.exists():
|
||||
print(f"Нужен файл {LIBRARY_FILE}")
|
||||
return
|
||||
if not CACHE_FILE.exists():
|
||||
print(f"Нужен файл {CACHE_FILE}")
|
||||
return
|
||||
|
||||
with open(LIBRARY_FILE, encoding="utf-8") as f:
|
||||
library = json.load(f)
|
||||
with open(CACHE_FILE, encoding="utf-8") as f:
|
||||
cache = json.load(f)
|
||||
|
||||
# кэш: ключи строковые "appid", значения — число или null
|
||||
cache_sizes = {int(k): v for k, v in cache.items()}
|
||||
|
||||
results = []
|
||||
for game in library:
|
||||
appid = game["appid"]
|
||||
name = game.get("name", "Unknown")
|
||||
raw = cache_sizes.get(appid)
|
||||
if raw is not None and isinstance(raw, (int, float)):
|
||||
size_gb = round(float(raw), 2)
|
||||
else:
|
||||
size_gb = None
|
||||
results.append({"appid": appid, "name": name, "size_gb": size_gb})
|
||||
|
||||
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(results, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"Записано {len(results)} записей в {OUTPUT_FILE}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user