#!/usr/bin/env python3
"""Cross-snapshot test: is a handle's newest post AND its engagement frozen across days?
If max(createdAt) never advances but views move, the account is genuinely quiet.
If both are frozen, GetXAPI is serving the same cached page (2026-10-19 condition)."""
import json
from datetime import datetime

RAW = "/home/kiro/trend-engine/trends/x/raw/"
DATES = ["2026-11-05", "2026-11-06", "2026-11-07", "2026-11-08", "2026-11-09"]
SUS = ["higgsfield", "higgsfield_ai", "runwayml", "pika_labs", "perplexity_ai",
       "AIWarper", "Flovaai", "openart_ai", "Kling_ai", "CharaspowerAI", "ItsMaryamAi"]

def pdt(s):
    return datetime.strptime(s, "%a %b %d %H:%M:%S %z %Y")

snaps = {}
for d in DATES:
    snaps[d] = json.load(open(RAW + f"scan_results_{d}_FULL.json"))["raw"]

for h in SUS:
    print(f"\n@{h}")
    prev = None
    for d in DATES:
        tw = snaps[d].get(h) or []
        if not tw:
            print(f"  {d}: NOT SCANNED")
            continue
        newest = max(tw, key=lambda t: pdt(t["createdAt"]))
        mx = pdt(newest["createdAt"]).strftime("%m-%d %H:%M")
        nid = newest.get("id")
        v = newest.get("viewCount"); l = newest.get("likeCount")
        # is the very same newest id as the previous day?
        same = "SAME-ID" if prev and nid == prev[0] else "new-id "
        print(f"  {d}: n={len(tw):2d} newest={mx} id={nid} {l}L/{v}V {same}")
        prev = (nid, v, l)
