#!/usr/bin/env python3
"""Cek jadwal type=story di 4 akun TSC + jam pending semua akun TSC."""
import json, datetime, collections
docs = json.load(open('/tmp/tsc_sched_all.json'))
AKUN = {"6a86a7e062caae1e04ff8244": "IG", "6a4bbc5920e4f4f195e52960": "Threads",
        "6a3b41ddc5ff4ce3a327542c": "FB", "6a4da7f520e4f4f195e796e1": "LinkedIn"}
WIB = datetime.timezone(datetime.timedelta(hours=7))
story = collections.Counter()
jam_pending = collections.Counter()
for d in docs:
    a = AKUN.get(d.get("accountId"))
    if not a:
        continue
    if d.get("type") == "story":
        story[a] += 1
    if d.get("status") == "pending" and d.get("scheduleAt"):
        t = datetime.datetime.fromisoformat(d["scheduleAt"].replace("Z", "+00:00")).astimezone(WIB)
        jam_pending[(a, t.strftime("%H:%M"))] += 1
print("jadwal type=story per akun TSC:", dict(story) or "TIDAK ADA")
print("jam pending per akun:")
for (a, j), c in sorted(jam_pending.items()):
    print(f"  {a:9s} {j} -> {c}")
