#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""注册 liyang 两个日跑 config (10步闭环)"""
import json

path = "/root/gov_crawler/daily_crawl_config.json"
cfg = json.load(open(path, encoding="utf-8"))
print(f"当前 {len(cfg)} 条")

# 检查是否已存在
existing = {c.get("name") for c in cfg}
new_items = []

if "溧阳市-政府信息公开" not in existing:
    new_items.append({
        "name": "溧阳市-政府信息公开",
        "script": "crawl_liyang_xxgk.py",
        "script_name": "crawl_liyang_xxgk.py",
        "incremental": True,
        "args": "--catid=43641,42151,40811,42170,42282,43445,42157,42201,42199,42238,42323,42186,42269,42205 --pages=5",
        "sync_mode": "direct_server",
        "enabled": True,
        "group": "江苏",
        "note": "前5页增量",
    })

if "溧阳市-通知公告" not in existing:
    new_items.append({
        "name": "溧阳市-通知公告",
        "script": "crawl_liyang_tzgg.py",
        "script_name": "crawl_liyang_tzgg.py",
        "incremental": True,
        "args": "--pages=5",
        "sync_mode": "direct_server",
        "enabled": True,
        "group": "江苏",
        "note": "前5页增量",
    })

if new_items:
    cfg.extend(new_items)
    json.dump(cfg, open(path, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
    print(f"新增 {len(new_items)} 条, 当前 {len(cfg)} 条")
    for it in new_items:
        print("  +", it["name"], it["args"])
else:
    print("已存在, 跳过")
