import json, io, os
from collections import Counter
BASE = "/data/www/files"
DATE = "20261106"
N = os.path.join(BASE, "snapshots", DATE)
S = os.path.join(BASE, "screenshots", DATE)
projs = json.load(io.open(os.path.join(BASE, "projects_%s.json" % DATE), encoding="utf-8"))
MARK = ["Access Verification", "Please slide to verify", "please slide to verify",
        "人机验证", "滑动验证", "暂无数据", "Security Verification", "访问验证",
        "Just a moment"]
bad = []
for i, p in enumerate(projs, 1):
    fp = os.path.join(N, "s%02d.txt" % i)
    txt = io.open(fp, encoding="utf-8", errors="ignore").read() if os.path.exists(fp) else ""
    body = txt.split("公告正文：", 1)[1] if "公告正文：" in txt else txt
    hits = [m for m in MARK if m.lower() in body.lower()]
    thin = len(body.strip()) < 600
    if hits and thin:
        sp = os.path.join(S, "p%02d.png" % i)
        bad.append((i, p["province"], os.path.getsize(sp) if os.path.exists(sp) else 0,
                    len(body.strip()), hits[:2], p["title"][:40]))
print("CAPTCHA/BLANK snapshots: %d" % len(bad))
for b in bad:
    print("  #%d [%s] png=%dB body=%dch %s | %s" % b)
print(Counter(b[1] for b in bad))
json.dump([b[0] for b in bad], io.open("/tmp/bad_1106.json", "w"))
