#!/usr/bin/env python3
import sys, re
from datetime import datetime, timedelta, timezone
sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from repliz_client import get_client
WIB = timezone(timedelta(hours=7))
c = get_client()
IDS = {
 "uky": "6ac41092eb0345aae470eca5",
 "tslaw": "6ac41092eb0345aae470ecaf",
 "tsc": "6ac41092e062926c48c3fff7",
 "das": "6ac41093eb0345aae470ecd1",
}
CJK = re.compile(r"[\u3000-\u303f\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uac00-\ud7af]")
for k, i in IDS.items():
    d = c.get_schedule(i)
    doc = d.get("docs", [d]) if isinstance(d, dict) and "docs" in d else (d[0] if isinstance(d, list) else d)
    desc = doc.get("description") or ""
    dt = datetime.fromisoformat(str(doc.get("scheduleAt")).replace("Z", "+00:00")).astimezone(WIB)
    links = re.findall(r"https?://\S+", desc)
    print(f"{k:6s} id={doc.get('_id')} status={doc.get('status')} type={doc.get('type')} "
          f"at={dt.strftime('%Y-%m-%d %H:%M')} WIB topic={doc.get('topic')!r} title={doc.get('title')!r}")
    print(f"       account={(doc.get('account') or {}).get('name')} len={len(desc)} replies={len(doc.get('replies') or [])} "
          f"cjk={'YA!' if CJK.search(desc) else 'no'} links={links}")
