INNER CODE UNIT · Python
read_history
lij768423-svg/grok-register-panel · batch_traffic.py:127
def read_history(path: str | os.PathLike[str]) -> dict:
history = _empty_history()
try:
raw = json.loads(Path(path).read_text(encoding="utf-8"))
except (OSError, ValueError, TypeError, json.JSONDecodeError):
return history
if not isinstance(raw, dict) or not isinstance(raw.get("batches"), list):
return history
history["batches"] = [
entry
for item in raw["batches"][-HISTORY_LIMIT:]
if (entry := _history_entry(item)) is not None
]
return history
def _history_sort_key(entry: dict) -> float:
try: