# -*- coding: utf-8 -*-
import re, io, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
html = open('index_main.html', encoding='utf-8').read()
m = re.search(r'const PROGRAMS=\[([\s\S]*?)\];\s*\n', html)
seg = m.group(1)
ids = re.findall(r'\{id:"([^"]+)"', seg)
deg = re.findall(r'deg:"([^"]+)"', seg)
phd = sum(1 for d in deg if 'PhD' in d or d == 'D' or 'Doctor' in d)
print('PROGRAMS total:', len(ids), 'unique:', len(set(ids)))
print('PhD:', phd, 'Master:', len(ids)-phd)
# 半核验页统计：ddl/tui/test 为空或待补
recs = re.findall(r'\{id:"[^"]+"[\s\S]*?(?=\{id:"|,?\n\];)', seg)
half = 0
for r in recs:
    if '待补' in r or re.search(r'ddl:""', r) or re.search(r'tui:""', r):
        half += 1
print('半核验/待补条数(粗略):', half)
