import json
from datetime import datetime

with open("/root/gov_crawler/daily_crawl_config.json") as f:
    c = json.load(f)

before = len(c["crawlers"])
c["crawlers"] = [x for x in c["crawlers"] if x.get("name") != "crawl_yq"]
removed = before - len(c["crawlers"])

if removed > 0:
    if isinstance(c["_count"], int):
        c["_count"] -= removed
    c["_stat"]["total"] -= removed
    c["_统计"] = "共{}个爬虫".format(c["_stat"]["total"])
    c["_更新日期"] = datetime.now().strftime("%Y-%m-%d %H:%M")

    with open("/root/gov_crawler/daily_crawl_config.json", "w") as f:
        json.dump(c, f, ensure_ascii=False, indent=2)
    print("removed: {}, total: {}".format(removed, c["_stat"]["total"]))
else:
    print("not found")
