Files

49 lines
1.4 KiB
Python

"""Verify every planned output exists and looks sane.
Usage: python verify_outputs.py <plan.json> <base_dir>
"""
import json
import os
import re
import sys
plan = json.load(open(sys.argv[1], encoding='utf-8'))
base = sys.argv[2]
missing = []
small = []
ok = []
for p in plan:
md = os.path.join(base, p['md_path'])
pdf = os.path.join(base, p['pdf_path'])
problems = []
if not os.path.exists(pdf) or os.path.getsize(pdf) < 20000:
problems.append('pdf')
if not os.path.exists(md):
problems.append('md-missing')
else:
t = open(md, encoding='utf-8').read()
cjk = len(re.findall(r'[\u4e00-\u9fff]', t))
if cjk < 900:
problems.append('md-short(%d)' % cjk)
for sec in ['摘要', '核心贡献', '方法', '实验', '结论']:
if sec not in t:
problems.append('missing-section:' + sec)
if problems:
small.append((p['id'], cjk, problems))
else:
ok.append((p['id'], cjk))
if problems and not any(x[0] == p['id'] for x in small):
missing.append((p['id'], problems))
print('OK: %d / %d' % (len(ok), len(plan)))
for i, c in ok:
print(' ok %s %d 汉字' % (i, c))
if small:
print('NEEDS ATTENTION:')
for i, c, pr in small:
print(' %s %d 汉字 %s' % (i, c, pr))
if missing:
print('MISSING FILES:')
for i, pr in missing:
print(' %s %s' % (i, pr))