#!/usr/bin/env python3
"""Ringkas jadwal Threads 26-27 Sep 2026 (WIB) + link di deskripsi."""
import json, re, sys
from datetime import datetime, timezone, timedelta
sys.path.insert(0, '/home/mantapman/.hermes/profiles/atun/workspace')
from repliz_client import ACC

WIB = timezone(timedelta(hours=7))
docs = json.load(open('/tmp/all_sched.json'))
names = {'studiosoft': ACC.STUDIOSOFT_THREADS, 'uky': ACC.UKY_THREADS,
         'tslaw': ACC.TSLAW_THREADS, 'tsc': ACC.TSC_THREADS, 'das': ACC.DAS_THREADS}
inv = {v: k for k, v in names.items()}
rows = []
for d in docs:
    sa = d.get('scheduleAt') or ''
    try:
        dt = datetime.fromisoformat(sa.replace('Z', '+00:00')).astimezone(WIB)
    except Exception:
        continue
    day = dt.strftime('%Y-%m-%d')
    if day not in ('2026-09-26', '2026-09-27'):
        continue
    acc = inv.get(d.get('accountId'), str(d.get('accountId'))[:8])
    desc = d.get('description') or ''
    links = re.findall(r'https?://[^\s\)\]"\']+', desc)
    rows.append((day, dt.strftime('%H:%M'), acc, d.get('status'), d.get('_id'), links))
for r in sorted(rows):
    print(r[0], r[1], f"{r[2]:11s}", f"[{r[3]}]", r[4], r[5])
print('total rows:', len(rows))
