#!/usr/bin/env python3
"""Fetch SEMUA jadwal Repliz (pagination) -> /tmp/repliz_full_<ts>.json"""
import json, sys, time
from repliz_client import get_client

c = get_client()
out = []
page = 1
while True:
    r = c.get_schedules(page=page, limit=100)
    docs = r.get("docs") or []
    out.extend(docs)
    total = r.get("totalDocs")
    print(f"page {page}: +{len(docs)} (total {len(out)}/{total})", flush=True)
    if not docs or len(out) >= (total or 0):
        break
    page += 1
    if page > 120:
        break
    time.sleep(0.3)

path = sys.argv[1] if len(sys.argv) > 1 else "/tmp/repliz_full.json"
json.dump(out, open(path, "w"))
print("saved", path, len(out))
