#!/usr/bin/env python3
"""Generate plain-text X Account Monitor report for 2026-09-10."""
import json
from datetime import datetime, timezone

TODAY = "2026-09-10"
d = json.load(open("/home/kiro/trend-engine/trends/x/scan_scored_%s.json" % TODAY))
core, filt, failed = d["core"], d["filtered"], d["failed"]

BIO = {
 "runwayml": "Runway AI - the platform of record for pro AI filmmaking",
 "CuriousRefuge": "Curious Refuge - AI filmmaker community",
 "nofilmschool": "No Film School - filmmaking news + industry reactions",
 "venturetwins": "Justine Moore (a16z) - AI video investor + Kling tutorials",
 "Kling_ai": "Kling AI - model releases, creator showcases",
 "paultrillo": "Paul Trillo - director, first commissioned Sora music video",
 "c_valenzuelab": "Cristobal Valenzuela - Runway CEO",
 "CorridorDigital": "Corridor Digital - VFX + AI tool reaction",
 "karenxcheng": "Karen X. Cheng - director, brand AI video (Adobe, Beats)",
 "higgsfield": "Higgsfield AI - model hub, contests, prompt libraries",
 "pika_labs": "Pika - social-first video generation",
 "EHuanglu": "el.cine (Elsa Huang) - AI film director, 128K",
 "azed_ai": "Amira Zairi - Adobe/Leonardo ambassador, tool teardowns",
 "JeffSynthesized": "Jeff - NeoCinema AI Studio, LA",
 "ai_filmmaker": "Dmitry Alekseev - surreal AI cinema",
 "visiblemaker": "Christian Fleischer - The Great Catspy (50M+ views)",
 "Magiermogul": "Particle Panic - $1M AI Film Award shortlist",
 "WuxiaRocks": "Wuxia Rocks - AI character consistency tracking",
 "JiamingSuen": "Jiaming Sun - AI/VFX, CorridorDigital collabs",
 "moonvalley": "Moonvalley - clean-trained film model startup",
 "higgsfield_ai": "Higgsfield AI (ops account)",
 "Chandan_Perla": "Chandan Perla - India AI Film Festival organizer",
}

def clean(t):
    return " ".join((t or "").split())

lines = []
lines.append("X ACCOUNT MONITOR -- %s" % TODAY)
lines.append("Watchlist: rising-accounts.md (%d accounts scanned, 3-day window from %s)" % (47, "2026-09-07"))
lines.append("Threshold: likes>=50 OR retweets>=10 OR views>=1000")
lines.append("=" * 62)
lines.append("")
lines.append("TOP 10 -- HIGH-ENGAGEMENT (AI-filmmaking relevant)")
lines.append("")
for i, e in enumerate(core[:10], 1):
    t = e["tweet"]
    url = "https://x.com/%s/status/%s" % (e["handle"], e["id"])
    lines.append("%d. @%s  [%s]" % (i, e["handle"], BIO.get(e["handle"], "")))
    lines.append("   %s" % clean(t.get("text", ""))[:220])
    lines.append("   %s" % url)
    lines.append("   Views: %s | Likes: %s | RT: %s | Replies: %s | Score: %.0f | %s"
                 % (f"{e['views']:,}", f"{e['likes']:,}", f"{e['rts']:,}", e["replies"], e["score"], e["date"]))
    lines.append("")

lines.append("=" * 62)
lines.append("")
lines.append("RUNNERS-UP (11-25, core)")
lines.append("")
for i, e in enumerate(core[10:25], 11):
    url = "https://x.com/%s/status/%s" % (e["handle"], e["id"])
    lines.append("%d. @%s -- %s | %sV %sL | %s" % (i, e["handle"], clean(e["tweet"].get("text",""))[:70], f"{e['views']:,}", f"{e['likes']:,}", e["date"]))
    lines.append("    %s" % url)
lines.append("")

lines.append("=" * 62)
lines.append("")
lines.append("NEWLY DISCOVERED (added %s) -- check for reclassification" % TODAY)
for h in ["AnthropicAI", "DiscussingFilm", "OpenAI"]:
    hits = [e for e in filt if e["handle"] == h]
    if hits:
        e = hits[0]
        url = "https://x.com/%s/status/%s" % (h, e["id"])
        lines.append("  @%s -- top: %sV %sL | %s | %s" % (h, f"{e['views']:,}", f"{e['likes']:,}", e["date"], url))
    else:
        lines.append("  @%s -- no qualifying tweets in window" % h)
lines.append("")
lines.append("  NOTE: @DiscussingFilm is film-industry news (fits Tier 3 Oscars/Academy coverage).")
lines.append("        @AnthropicAI / @OpenAI are AI-lab accounts, not filmmaking. Recommend:")
lines.append("        move DiscussingFilm -> CORE, keep the other two filtered.")
lines.append("")

lines.append("=" * 62)
lines.append("")
lines.append("FILTERED (auto-discovered, %d qualifying tweets)" % len(filt))
top_filt = {h: max([e for e in filt if e["handle"] == h], key=lambda x: x["score"]) for h in set(e["handle"] for e in filt)}
for h, e in sorted(top_filt.items(), key=lambda kv: -kv[1]["score"])[:12]:
    lines.append("  @%s -- best %sV %sL | %s" % (h, f"{e['views']:,}", f"{e['likes']:,}", e["date"]))
lines.append("")

lines.append("=" * 62)
lines.append("")
inactive = [h for h in BIO if not any(e["handle"] == h for e in core)]
lines.append("INACTIVE CORE ACCOUNTS (no qualifying tweet in 3-day window): %d" % len(inactive))
lines.append("  " + ", ".join("@" + h for h in inactive))
lines.append("")
lines.append("  These are all Tier 2 filmmaker voices -- typically <50 likes/post.")
lines.append("  Not a signal of account death; threshold is tuned for Tier 1 reach.")
lines.append("")

lines.append("SCAN HEALTH")
lines.append("  Accounts scanned: 47 | Failures: %d %s" % (len(failed), failed))
lines.append("  Core qualifying: %d | Filtered qualifying: %d" % (len(core), len(filt)))
lines.append("  Top account: @venturetwins (29,031 score -- 561K views on one post)")

out = "\n".join(lines)
p = "/home/kiro/trend-engine/trends/x/account-monitor/%s_account-monitor.txt" % TODAY
open(p, "w").write(out)
print(out)
print("\n\nSAVED: %s" % p)
