#!/usr/bin/env python3
"""Analisis cache: semua post FB SS (pending+sukses) & jejak artikel kandidat LI."""
import json
import sys
from datetime import datetime, timezone

WS = "/home/mantapman/.hermes/profiles/atun/workspace"
sys.path.insert(0, WS)
from repliz_client import ACC

docs = json.load(open(WS + "/_ss_docs_cache.json"))
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")

print("=== SEMUA FB SS (urut waktu) ===")
rows = []
for s in docs:
    if s.get("accountId") != ACC.STUDIOSOFT_FB:
        continue
    rows.append(((s.get("scheduleAt") or "")[:19], (s.get("status") or ""), (s.get("title") or "")))
for r in sorted(rows)[-30:]:
    print("%s | %-8s | %s" % r)

print("\n=== KANDIDAT LI (artikel 15-25 Okt) jejak di 4 kanal SS ===")
cands = [
    ("riset-kompetitor-seo", "Riset Kompetitor SEO"),
    ("kata-kunci-lokal", "Kata Kunci Lokal"),
    ("biaya-iklan-google-bisnis-kecil", "Biaya Iklan Google untuk Bisnis Kecil"),
    ("landing-page-vs-website-mana-yang-dibuat-dulu", "Landing Page vs Website"),
    ("audit-seo-teknis-12-pemeriksaan", "Audit SEO Teknis"),
    ("laporan-seo-bulanan-angka-wajib", "Laporan SEO Bulanan"),
    ("kontrak-digital-agency-pasal-wajib", "Kontrak Digital Agency"),
]
names = {ACC.STUDIOSOFT_THREADS: "THR", ACC.STUDIOSOFT_LINKEDIN: "LI",
         ACC.STUDIOSOFT_FB: "FB", ACC.STUDIOSOFT_IG: "IG"}
for slug, frag in cands:
    hits = []
    for s in docs:
        if s.get("accountId") not in names:
            continue
        t = (s.get("title") or "").lower()
        if frag.lower() in t:
            hits.append("%s/%s/%s" % (names[s["accountId"]],
                                      (s.get("scheduleAt") or "")[:16],
                                      (s.get("status") or "")[:4]))
    print("%-45s -> %s" % (slug, ", ".join(hits) if hits else "0 HIT"))
