Files

46 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Extract bounded loading intervals from supplied Client.log files; never emit text."""
import argparse
import datetime as dt
import hashlib
import json
import re
from pathlib import Path
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('logs', nargs='+', type=Path)
args = parser.parse_args()
seen = set()
results = []
for path in args.logs:
blob = path.read_bytes()
digest = hashlib.sha256(blob).hexdigest()
if digest in seen:
continue
seen.add(digest)
record = dict(path=str(path), sha256=digest, bytes=len(blob), loads=[], hotfixes=[], unmatched=[])
load = hotfix = None
for line in blob.decode(errors='replace').splitlines():
match = re.match(r'(\d+/\d+ \d+:\d+:\d+\.\d+)', line)
if not match:
continue
stamp = dt.datetime.strptime('2026/' + match[1], '%Y/%m/%d %H:%M:%S.%f')
if 'Loading Screen Enable' in line:
if load is not None:
record['unmatched'].append(dict(kind='replaced_enable', at=load.isoformat()))
load = stamp
if 'Loading Screen Disable' in line and load is not None:
record['loads'].append(dict(start=load.isoformat(), end=stamp.isoformat(), seconds=(stamp-load).total_seconds()))
load = None
if 'Initial Hotfixes: Requested' in line:
hotfix = stamp
if 'Initial Hotfixes: Applied' in line and hotfix is not None:
record['hotfixes'].append(dict(start=hotfix.isoformat(), end=stamp.isoformat(), seconds=(stamp-hotfix).total_seconds()))
hotfix = None
if load is not None:
record['unmatched'].append(dict(kind='unclosed_enable', at=load.isoformat()))
if hotfix is not None:
record['unmatched'].append(dict(kind='unclosed_hotfix', at=hotfix.isoformat()))
results.append(record)
print(json.dumps(dict(calendar_year=2026, inputs=results), indent=2))