#!/usr/bin/env python3
"""2026-10-24 verify: offer grep, full texts of key posts, tier-2, film AI audit, labs."""
import json, re
from datetime import datetime, timezone

D = "/home/kiro/trend-engine/trends/x/raw/scan_results_2026-10-24_FULL.json"
d = json.load(open(D))
raw, qual = d["raw"], d["qualifying"]

IRRELEVANT = set("""AIBuzzNews AIGuideHQ AITECHio AIFrontliner TheAIColony AITOPIAai AISuperDomain
GoogleLabs GoogleAI DonutAI cladlabs FaithJaiye2187 KammelaBala MyStageAI AlexStudio44
AI_with_jasmin Ai_Vaidehi ChrisLaubAI OpenAI AnthropicAI CINEMA505 AIScottAdams AI_Jasonyu AIByLeo""".split())
FILM = {"DiscussingFilm", "nofilmschool"}
LABS = {"OpenAI", "AnthropicAI"}
TIER2 = ["CuriousRefuge","paultrillo","JeffSynthesized","ai_filmmaker","Magiermogul",
         "JiamingSuen","Chandan_Perla","visiblemaker","moonvalley","CorridorDigital"]

PATTERNS = [
 r"\b\d{1,3}% ?off", r"\bfree\b", r"\bcoupon\b", r"\bpromo\b", r"\bdiscount",
 r"\$\d", r"\bcredits?\b", r"\btrial\b", r"\bgiveaway\b", r"\bthrough \w+ \d{1,2}",
 r"\buntil \w+ \d{1,2}", r"\bdeadline\b", r"\bends?\b", r"\bblack friday\b",
 r"\bunlimited\b", r"\bcheaper\b", r"\bper second\b", r"/sec", r"\bprice\b",
 r"\bplan\b", r"\bsubscription\b", r"\bcashback\b", r"\bup to\b", r"\bdeal\b",
 r"\b\d+ ?days? left\b", r"\bopen source\b", r"\bfree to try\b",
]
rx = re.compile("|".join(PATTERNS), re.I)

print("=== OFFER / PRICE GREP (in-window text, all buckets) ===")
for q in sorted(qual, key=lambda q: -q["score"]):
    if rx.search(q["text"]):
        print("%-14s|%s|%dL/%dV|%s" % (q["handle"], q["date"], q["likes"], q["views"],
              q["text"][:260].replace("\n", " ")))

print("\n=== TIER-2 STATUS ===")
for h in TIER2:
    n = sum(1 for q in qual if q["handle"] == h)
    best = max([q for q in qual if q["handle"] == h], key=lambda q: q["score"], default=None)
    if best:
        print("%-16s qualifying=%d best=%dL/%dV %s" % (h, n, best["likes"], best["views"], best["text"][:90].replace("\n"," ")))
    else:
        print("%-16s qualifying=0" % h)
silent = [h for h in TIER2 if not any(q["handle"] == h for q in qual)]
print("SILENT %d/%d: %s" % (len(silent), len(TIER2), ", ".join("@"+h for h in silent)))

print("\n=== FILM INDUSTRY ===")
AITERM = re.compile(r"(?<![a-z])(ai|a\.i\.|artificial intelligence|generative|gen ?ai|sora|runway|midjourney|veo|kling|seedance|prompt|machine learning|deepfake|synthetic)(?![a-z])", re.I)
for h in ("DiscussingFilm","nofilmschool","CINEMA505"):
    qs = [q for q in qual if q["handle"] == h]
    hits = [q for q in qs if AITERM.search(q["text"])]
    print("%s qualifying=%d AI-term hits=%d" % (h, len(qs), len(hits)))
    for q in hits:
        print("   -> %dL/%dV %s | %s" % (q["likes"], q["views"], q["url"], q["text"][:200].replace("\n"," ")))

print("\n=== AI LABS ===")
for q in sorted([q for q in qual if q["handle"] in LABS], key=lambda q: -q["score"]):
    print("%-12s|%s|%dL/%dV|%s" % (q["handle"], q["date"], q["likes"], q["views"], q["text"][:200].replace("\n"," ")))

print("\n=== KEY FULL TEXTS ===")
keys = [
 ("azed_ai", "Dreamina"),
 ("azed_ai", "0.29"),
 ("Flovaai", None),
 ("higgsfield_ai", "Content Factory"),
 ("higgsfield_ai", "Ideogram"),
 ("venturetwins", "Kling 4"),
 ("AIWarper", "OPUS"),
 ("EHuanglu", "Tykwer"),
 ("c_valenzuelab", "Control"),
 ("CharaspowerAI", "Starlight"),
]
seen = set()
for h, needle in keys:
    for q in qual:
        if q["handle"] != h: continue
        if needle and needle.lower() not in q["text"].lower(): continue
        if q["url"] in seen: continue
        seen.add(q["url"])
        print("\n--- @%s %s %dL/%dRT/%dR/%dV score=%d\n%s\n%s" % (
            h, q["date"], q["likes"], q["rt"], q["replies"], q["views"], q["score"], q["url"], q["text"]))
