#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Verifikasi akhir: sisa jadwal @ukyhandoko (dan akun lain) yang topic/title-nya memuat 'growth'."""
from repliz_client import get_client

UKY = "6a334e89c5ff4ce3a3225a48"


def semua(c):
    docs, page = [], 1
    while True:
        r = c.get_schedules(page=page, limit=100)
        d = r.get("docs") or []
        docs.extend(d)
        if not d or len(docs) >= (r.get("totalDocs") or 0) or page > 60:
            break
        page += 1
    return docs


def main():
    c = get_client()
    rows = semua(c)
    print("total jadwal:", len(rows))
    uky_hits = [x for x in rows
                if (x.get("accountId") or (x.get("account") or {}).get("_id")) == UKY
                and ("growth" in (x.get("topic") or "").lower() or "growth" in (x.get("title") or "").lower())]
    print("uky topic/title memuat 'growth':", len(uky_hits))
    for x in uky_hits:
        print("  ", x.get("_id"), repr(x.get("topic")), repr(x.get("title")))

    lain = [x for x in rows
            if (x.get("accountId") or (x.get("account") or {}).get("_id")) != UKY
            and "growth" in (x.get("topic") or "").lower()]
    per_akun = {}
    for x in lain:
        nm = (x.get("account") or {}).get("name") or x.get("accountId")
        per_akun[nm] = per_akun.get(nm, 0) + 1
    print("\ntopic 'growth' di akun LAIN (belum disentuh):", per_akun)


if __name__ == "__main__":
    main()
