#!/usr/bin/env python3
"""Cari jadwal Threads TSC (dan akun lain) yang punya replies, plus cari post ID Deihy3pie4C."""
import json, datetime, collections
docs = json.load(open('/tmp/tsc_sched_all.json'))
WIB = datetime.timezone(datetime.timedelta(hours=7))

print("== cari id Deihy3pie4C di semua field ==")
hit = 0
for d in docs:
    j = json.dumps(d)
    if "Deihy3pie4C" in j or "Deihy3pie" in j:
        hit += 1
        print(json.dumps({k: d.get(k) for k in ('_id', 'accountId', 'type', 'scheduleAt', 'status', 'title')}, indent=1))
print("hit:", hit)

print("\n== jadwal TSC Threads yang punya replies ==")
TSC_TH = "6a4bbc5920e4f4f195e52960"
for d in sorted([x for x in docs if x.get('accountId') == TSC_TH],
                key=lambda x: x.get('scheduleAt') or ''):
    r = d.get('replies') or []
    if r:
        t = datetime.datetime.fromisoformat(d['scheduleAt'].replace('Z', '+00:00')).astimezone(WIB)
        print(f"{t.strftime('%Y-%m-%d %H:%M')} {d.get('status')} {d.get('type')} replies={len(r)} id={d.get('_id')}")
        print("   post:", (d.get('description') or '')[:120].replace('\n', ' '))
        for i, x in enumerate(r, 1):
            print(f"   reply{i}:", json.dumps(x)[:300])
