#!/usr/bin/env python3
import json
import sys
from collections import Counter
from pathlib import Path

tid = (sys.argv[1] if len(sys.argv) > 1 else "40CC").upper()
p = Path.home() / "EtherGold/dev/data/events.jsonl"
c = Counter()
n = 0
for line in p.read_text(errors="replace").splitlines():
    if tid not in line.upper():
        continue
    n += 1
    try:
        e = json.loads(line)
    except Exception:
        continue
    c[(e.get("ev"), e.get("msg") or e.get("sent_msg"))] += 1
print(f"tid_lines={n}")
for k, v in c.most_common(40):
    print(v, k)
