#!/usr/bin/env python3
"""Scan SEMUA jadwal pending Threads: cari @mention akun kita sendiri (pelanggaran aturan 1 Sep)."""
import json
import re
from datetime import datetime, timedelta, timezone

WIB = timezone(timedelta(hours=7))
docs = json.load(open("/tmp/scheds_1013.json"))
THREADS_ACC = {
    "6a334e89c5ff4ce3a3225a48": "uky",
    "6a335b9ec5ff4ce3a3225c2a": "studiosoft",
    "6a35f8b7c5ff4ce3a322b2ed": "tslaw",
    "6a39e461c5ff4ce3a3233e09": "das",
    "6a4bbc5920e4f4f195e52960": "tsc",
    "6a44ed1920e4f4f195d8ecf7": "everybe",
    "6a5f4af462caae1e04e8b9a6": "leit",
    "6a86d84b62caae1e04fff12c": "soto",
}
SELF = re.compile(r"@(studiosoft\.id|ukyhandoko|_ukyhandoko|tslaw\.id|dasindonesia|theskincodeclinic|everybe|leit)", re.I)
MENT = re.compile(r"@[A-Za-z0-9_.]+")

found = 0
for d in sorted(docs, key=lambda x: str(x.get("scheduleAt"))):
    aid = d.get("accountId")
    if aid not in THREADS_ACC:
        continue
    if d.get("status") not in ("pending", "draft"):
        continue
    desc = d.get("description") or ""
    hits = SELF.findall(desc)
    if hits:
        found += 1
        try:
            dt = datetime.fromisoformat(str(d["scheduleAt"]).replace("Z", "+00:00")).astimezone(WIB)
            when = dt.strftime("%Y-%m-%d %H:%M")
        except Exception:
            when = str(d.get("scheduleAt"))
        print(f"{when} {THREADS_ACC[aid]:11s} id={d.get('_id')} status={d.get('status')} hits={hits}")
        print(f"   deskripsi: {desc[-260:]!r}")
print("total pelanggaran mention-akun-sendiri (pending/draft):", found)
