#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Lihat ritme tayang artikel tslaw.id (published & future) untuk cari slot yang rapi."""
import sys
from collections import Counter

sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
import tslaw_wp as T  # noqa: E402

for status in ("future", "publish", "draft"):
    try:
        r = T.get("posts", {"per_page": 100, "status": status,
                            "_fields": "id,slug,title,date,status,link"})
        data = r.json()
    except Exception as e:
        print(f"[{status}] GAGAL: {e}")
        continue
    print(f"\n=== {status} ({len(data)}) ===")
    for p in sorted(data, key=lambda x: x["date"], reverse=True)[:20]:
        print(f"  {p['date'][:16]} #{p['id']:5} {p['title']['rendered'][:66]}")
    if status != "draft":
        jam = Counter(p["date"][11:16] for p in data)
        print(f"  jam tayang yang dipakai: {dict(jam.most_common(6))}")
