import json, re
base="/home/kiro/trend-engine/trends/x/raw/"
cur=json.load(open(base+"scan_results_2026-10-17_FULL.json"))
q=cur["qualifying"]; raw=cur["raw"]

# author sanity on the viral outlier
for t in raw["CharaspowerAI"]:
    if t.get("likeCount")==70648:
        a=t.get("author") or {}
        print("VIRAL POST author:", json.dumps(a)[:300])
        print("bookmarks:", t.get("bookmarkCount"), "quotes:", t.get("quoteCount"), "replies:", t.get("replyCount"), "source:", t.get("source"))
        print("url:", t.get("url"), "| twitterUrl:", t.get("twitterUrl"))
        print("id:", t.get("id"))

# account-level reality check: CharaspowerAI all posts
print("\nCharaspowerAI all fetched likeCounts:", sorted([t.get("likeCount",0) for t in raw["CharaspowerAI"]], reverse=True))

# film bucket composition
FILM={"DiscussingFilm","nofilmschool"}
AI=re.compile(r"(?<!\bfilm )(?<!\bfilm-)(?<!\bscreenplay )(?<!\bscreenplay-)\bprompt|\b(ai\b|a\.i\.|artificial intelligence|machine learning|generative|diffusion|midjourney|stable diffusion|sora|runway|pika|kling|veo|seedance|nano banana|hunyuan|wan 2|luma|heygen|synthesia|deepfake|neural|vfx|cgi|motion capture|unreal engine|3d render|(ai|3d|generated) ?animation|gpt|llm|agentic)", re.I)
from collections import Counter
for h in FILM:
    rows=[t for t in q if t["handle"]==h]
    hits=[t for t in rows if AI.search(t["text"] or "")]
    print(f"\n{h}: {len(rows)} qualifying, {len(hits)} AI-term matches")
    for t in hits: print("   ", t["date"][:16], f"{t['likes']}L {t['views']}V", "::", t["text"].replace("\n"," ")[:200])

print("\nTOTAL film bucket:", len([t for t in q if t['handle'] in FILM]))
print("LABS rows:")
for t in q:
    if t["handle"] in ("OpenAI","AnthropicAI"):
        print("   ", t["handle"], t["date"][:16], f"{t['likes']}L {t['views']}V", t["text"].replace("\n"," ")[:110])
print("labs count:", len([t for t in q if t['handle'] in ('OpenAI','AnthropicAI')]))
print("core count:", len([t for t in q if t['handle'] in set('runwayml CuriousRefuge venturetwins Kling_ai paultrillo c_valenzuelab karenxcheng higgsfield pika_labs EHuanglu azed_ai JeffSynthesized ai_filmmaker Magiermogul WuxiaRocks JiamingSuen higgsfield_ai Chandan_Perla CharaspowerAI AIWarper nofilmschool Flovaai AI__TSUBAKI'.split())]) - len([t for t in q if t['handle']=='nofilmschool']))
print("total:", len(q))
