27 lines
774 B
Python
27 lines
774 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
历史爬取记录回填数据库 (幂等, 可重复执行)
|
|
|
|
用法:
|
|
python backfill.py # 回填所有任务的历史记录
|
|
python backfill.py <task_id> ... # 只回填指定任务
|
|
|
|
说明:
|
|
- 将本地 data/ 中的任务/运行/爬取结果(含成功与失败)全量写入 MySQL
|
|
- 网页内容不入库, 只写元数据; 重复执行不会产生重复记录
|
|
"""
|
|
import sys
|
|
|
|
import db
|
|
import store
|
|
|
|
if __name__ == "__main__":
|
|
ids = [a for a in sys.argv[1:] if a.strip()] or None
|
|
db.init_db()
|
|
stats = db.sync_all_history(ids)
|
|
if ids:
|
|
print(f"[backfill] 已回填 {len(ids)} 个任务: {stats}")
|
|
else:
|
|
print(f"[backfill] 已回填全部任务: {stats}")
|