import re import time from datetime import datetime as DateTime from functools import cache from pathlib import Path import requests reg = re.compile(r"\[(?P\d{4})-(?P\d{2})-(?P\d{2}) (?P\d{2}):(?P\d{2}):(?P\d{2})\] Still replaying (?P\d+) \(\d{2}%, (?P\d+)\/(?P\d+)\)") @cache def appids(): return { app["appid"]: app["name"] for app in requests.get( "https://api.steampowered.com/ISteamApps/GetAppList/v2/" ).json()["applist"]["apps"] } def names_shadercache(): return [appids()[appid] for appid in appids_shadercache()] def mktime(result: dict) -> DateTime: return DateTime( *( int(result[name]) for name in ("year", "month", "day", "hour", "minute", "second") ) ) def read_log(): with Path.home().joinpath(".local/share/Steam/logs/shader_log.txt").open() as fd: while True: line = fd.readline().rstrip() if not line: continue if match := reg.search(line): result = match.groupdict() dt = mktime(result) game = appids().get(int(result["appid"]), "Unknown") progress = int(result["done"]) / int(result["total"]) print("\033c", end="") print(f"[{dt}] [{progress:06.2%}] {game}") if __name__ == "__main__": read_log() # [2024-05-04 13:57:35] Still replaying 730 (80%, 1572280/1941272).