import json, re, glob
from collections import Counter
p="/home/kiro/trend-engine/trends/x/raw/scan_results_%s_FULL.json"
a=json.load(open(p%"2026-10-13")); b=json.load(open(p%"2026-10-12"))
ha,hb=set(a["handles"]),set(b["handles"])
print("count", len(a["handles"]), len(b["handles"]))
print("ADDED", sorted(ha-hb), "REMOVED", sorted(hb-ha))
print("failures", a["failures"])
q=a["qualifying"]; print("total", len(q))
IRR={"AIBuzzNews","AIGuideHQ","AITECHio","AIFrontliner","TheAIColony","AITOPIAai","GoogleLabs","GoogleAI","DonutAI","cladlabs","FaithJaiye2187","KammelaBala","MyStageAI","AlexStudio44","AI_with_jasmin","Ai_Vaidehi","ChrisLaubAI","CINEMA505","AIScottAdams","AISuperDomain","AI_Jasonyu","AIByLeo"}
FI={"DiscussingFilm","nofilmschool"}; LAB={"OpenAI","AnthropicAI"}
core=[x for x in q if x["handle"] not in IRR and x["handle"] not in FI and x["handle"] not in LAB]
print("core",len(core),"film-industry",len([x for x in q if x["handle"] in FI]),
      "irrelevant",len([x for x in q if x["handle"] in IRR]),"labs",len([x for x in q if x["handle"] in LAB]))
c=Counter(x["handle"] for x in core); print("core handle counts:", c.most_common(12))
top10=core[:10]
print("top10 handles:", [x["handle"] for x in top10])
hist=[]
for f in sorted(glob.glob("/home/kiro/trend-engine/trends/x/raw/scan_results_*_FULL.json")):
    d=re.search(r"(\d{4}-\d{2}-\d{2})",f).group(1)
    if d>="2026-09-26":
        j=json.load(open(f)); hist.append((d,len(j["qualifying"])))
print("trend", hist)
