# -*- coding: utf-8 -*-
import io, sys, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")

html = open("index_main.html", encoding="utf-8").read()
DET = "details/cornell-cf3bfaf.html"
PID = "cornell-mse-meng"

# PROGRAMS 条目
m = re.search(r'\{id:"' + PID + r'".*?\}', html, re.S)
assert m, "PROGRAMS 条目未找到"
entry = m.group(0)
lvl = re.search(r'lvl:"([^"]+)"', entry).group(1)
deg = re.search(r'deg:"([^"]+)"', entry).group(1)
stem = re.search(r'stem:(\d)', entry).group(1)
cls = re.search(r'cls:"([^"]*)"', entry).group(1)
print("PROGRAMS:", PID, "| lvl", lvl, "| deg", deg, "| stem", stem, "| test", cls)

# 引用计数
print("PROGRAMS url 引用:", html.count('url:"' + DET + '"'))
print("CATD det 引用:", len(re.findall(r'\[[^\]]*"'+DET+r'"[^\]]*\]', html)))
vd = re.search(r'const VERIFIED_DETAILS=new Set\(\[(.*?)\]\);', html, re.S).group(1)
print("VD 登记:", ('"' + DET + '"') in vd)
print("det 磁盘存在:", os.path.exists(DET))

# 六卡 h2
page = open(DET, encoding="utf-8").read()
h2 = re.findall(r"<h2>(.*?)</h2>", page)
print("详情页 h2 数:", len(h2))
for h in h2:
    print("  -", h)

# 硕博计数复核
progs = re.findall(r'lvl:"([md])"', html)
print("PROGRAMS lvl 分布: m", progs.count("m"), "d", progs.count("d"))
