#!/usr/bin/env python3
"""Add tl.gov.cn to daily_crawl_config.json"""
import json

CONFIG_PATH = "/root/gov_crawler/daily_crawl_config.json"

with open(CONFIG_PATH) as f:
    cfg = json.load(f)

# Check if already exists
existing = any(c["name"] == "铜陵市生态环境局-最新公开" for c in cfg["crawlers"])
if existing:
    print("Already exists in config")
else:
    new_entry = {
        "name": "铜陵市生态环境局-最新公开",
        "script": "crawl_tl.py",
        "args": "5",
        "incremental": True,
        "sync_mode": "direct_server",
        "enabled": True,
        "group": "安徽",
        "note": "铜陵市生态环境局信息公开-最新公开, showList/770/1948, 15条/页, 29页共422条, a.biaoti-title提取(title属性完整标题), div#zoom正文含表格HTML"
    }
    cfg["crawlers"].append(new_entry)
    
    with open(CONFIG_PATH, "w") as f:
        json.dump(cfg, f, ensure_ascii=False, indent=2)
    print("Added tl.gov.cn to daily config")
    print(f"Total crawlers: {len(cfg['crawlers'])}")
