#!/usr/bin/env python3
"""Film-bucket hand audit (bare-ai + STRONG_TERMS), board-wide launch sweep,
and the NEW-since-yesterday set (posts created on/after 2026-11-08 00:00 UTC)."""
import json, re
from datetime import datetime, timezone

RAW = "/home/kiro/trend-engine/trends/x/raw/"
d = json.load(open(RAW + "scan_results_2026-11-09_FULL.json"))
p = json.load(open(RAW + "scan_results_2026-11-08_FULL.json"))
raw, q = d["raw"], d["qualifying"]
def pdt(s): return datetime.strptime(s, "%a %b %d %H:%M:%S %z %Y")
now = datetime.now(timezone.utc)
NEWCUT = datetime(2026,11,8,0,0, tzinfo=timezone.utc)

print("=== FILM BUCKET HAND AUDIT (DiscussingFilm / nofilmschool) ===")
STRONG = re.compile(r"\b(a\.i\.|seedance|kling|runway|veo|sora|minimax|hailuo|higgsfield|midjourney|"
                    r"nano ?banana|chatgpt|gemini|generative|vfx|ai film|aifilm|deepfake|comfyui|"
                    r"diffusion|(ai|3d|generated) ?animation)\b", re.I)
BARE = re.compile(r"(?<![a-z0-9])a\.?i\.?(?![a-z0-9])", re.I)
film = [x for x in q if x["handle"] in {"DiscussingFilm","nofilmschool"}]
print(f"film qualifying: {len(film)}")
nstrong=nbare=0
for x in film:
    t = x["text"]
    s = STRONG.search(t); b = BARE.search(t)
    if s: nstrong+=1
    if b and not s: nbare+=1
    if s or b:
        print(f"  @{x['handle']} {x['date']} {x['likes']}L/{x['views']}V match={s.group(0) if s else b.group(0)!r}")
        print(f"     {t[:190]}")
print(f"STRONG_TERMS matches: {nstrong} | bare-ai-only matches: {nbare}")

print("\n=== NEW SINCE 2026-11-08 00:00 (all handles, originals only) ===")
for h, tw in raw.items():
    for t in tw:
        if t.get("retweeted_tweet") or t.get("type") != "tweet": continue
        dt = pdt(t["createdAt"])
        if dt < NEWCUT: continue
        if (t.get("likeCount") or 0) < 50 and (t.get("viewCount") or 0) < 1000: continue
        print(f"@{h:17s} {dt.strftime('%m-%d %H:%M')} {t.get('likeCount'):>6}L/{t.get('viewCount'):>9}V "
              f"rate={(t.get('likeCount') or 0)/max(t.get('viewCount') or 1,1)*100:5.2f}% :: {(t.get('text') or '')[:150]}".replace("\n"," "))
