#!/usr/bin/env python3
"""Add xj config and rebuild FTS"""
import json

with open('/root/daily_crawl_config.json', 'r') as f:
    cfg = json.load(f)

crawlers = cfg['crawlers']
print('Current crawlers: %d' % len(crawlers))

new_entry = {
    "name": "新疆生态环境厅项目拟审批公示",
    "script": "crawl_xj_hjyxpjnsp.py",
    "incremental": True,
    "enabled": True,
    "run_dir": "/root/gov_crawler",
    "note": "TRS, createPageHTML 10/页, 100条近1年"
}
crawlers.append(new_entry)
cfg['crawlers'] = crawlers
cfg['_stat'] = 'crawlers: %d' % len(crawlers)

with open('/root/daily_crawl_config.json', 'w') as f:
    json.dump(cfg, f, ensure_ascii=False, indent=2)

idx = len(crawlers) - 1
print('Added entry #%d: %s' % (idx, new_entry['name']))
print('Total: %d' % len(crawlers))
