#!/usr/bin/env python3
"""Peta akun Facebook & LinkedIn: bikin/jadwal/status/last post + contoh link caption."""
import json, re, collections, datetime

accs = json.load(open("/tmp/reach_accs.json"))
sch = json.load(open("/tmp/reach_schedules.json"))

by_id = {a["_id"]: a for a in accs}
for plat in ("facebook", "linkedin"):
    print("=" * 84)
    print(plat.upper())
    print("=" * 84)
    rows = [a for a in accs if (a.get("type") or "").lower() == plat]
    for a in rows:
        aid = a["_id"]
        mine = [s for s in sch if s.get("accountId") == aid]
        st = collections.Counter(s.get("status") for s in mine)
        last = max((s.get("scheduleAt", "") for s in mine), default="")
        future = [s for s in mine if s.get("status") == "pending"
                  and s.get("scheduleAt", "") > datetime.datetime.utcnow().isoformat()]
        print(f"{a['name'][:30]:30s} | @{a.get('username','')[:22]:22s} | {aid}")
        print(f"    jadwal={len(mine):4d} {dict(st)} | pending ke depan={len(future)} | terakhir={last[:10]}")
    print()
