# -*- coding: utf-8 -*-
"""挑出评论抓取不完整的作品，生成重抓清单"""
import glob, json, os

ROOT = r"D:\Deepseek\douyin_fengdaquan"
rows = []
for fp in sorted(glob.glob(os.path.join(ROOT, "comments_raw", "*.json"))):
    j = json.load(open(fp, encoding="utf-8"))
    total = j.get("total_comments") or 0
    got = len(j.get("comments") or [])
    if total >= 15 and got < max(10, total * 0.85):
        rows.append({"id": j["aweme_id"], "got": got, "total": total})
rows.sort(key=lambda r: r["total"] - r["got"], reverse=True)
json.dump([r["id"] for r in rows], open(os.path.join(ROOT, "_refetch_ids.json"), "w", encoding="utf-8"), indent=1)
print("需要重抓 %d 个:" % len(rows))
for r in rows:
    print("  %s  已有 %d / 共 %d" % (r["id"], r["got"], r["total"]))
    os.remove(os.path.join(ROOT, "comments_raw", r["id"] + ".json"))
