#!/usr/bin/env python3
"""Cek jadwal Threads per akun untuk rentang tanggal WIB (default 25-27 Sep 2026)."""
import sys, json
from datetime import datetime, timezone, timedelta
sys.path.insert(0, '/home/mantapman/.hermes/profiles/atun/workspace')
from repliz_client import get_client, ACC

WIB = timezone(timedelta(hours=7))
DATES = sys.argv[1:] or ['2026-09-25', '2026-09-26', '2026-09-27']
c = get_client()
docs = []
for p in range(1, 150):
    r = c.get_schedules(page=p, limit=100)
    b = r.get('docs', [])
    if not b:
        break
    docs += b
    if len(b) < 100:
        break
print('total schedules:', len(docs))
json.dump(docs, open('/tmp/all_sched.json', 'w'), ensure_ascii=False)
names = {'studiosoft': ACC.STUDIOSOFT_THREADS, 'uky': ACC.UKY_THREADS,
         'tslaw': ACC.TSLAW_THREADS, 'tsc': ACC.TSC_THREADS, 'das': ACC.DAS_THREADS}
for k, aid in names.items():
    print('=' * 12, k)
    for d in docs:
        if d.get('accountId') != aid:
            continue
        sa = d.get('scheduleAt') or ''
        try:
            dt = datetime.fromisoformat(sa.replace('Z', '+00:00')).astimezone(WIB)
        except Exception:
            continue
        if dt.strftime('%Y-%m-%d') in DATES:
            desc = (d.get('description') or '').replace('\n', ' | ')
            print(f"  {dt.strftime('%Y-%m-%d %H:%M')} [{d.get('status')}] {(d.get('title') or '')[:40]} :: {desc[:130]}")
