import json, os, ssl, urllib.request, urllib.error, hashlib

BASE = os.path.dirname(os.path.abspath(__file__))
cands = json.load(open(os.path.join(BASE, '_cands25.json'), encoding='utf-8'))
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

def probe(url):
    req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'})
    try:
        with urllib.request.urlopen(req, timeout=8, context=ctx) as r:
            b = r.read()
            return r.status, len(b), None
    except urllib.error.HTTPError as e:
        return e.code, 0, 'http'
    except Exception as e:
        return None, 0, type(e).__name__

# 按校分组看字节数是否一致（聚合页特征）
school_bytes = {}
results = []
for x in cands[:60]:
    st, n, err = probe(x['url'])
    results.append((x['s'], x['en'][:38], x['deg'], st, n, err, os.path.basename(x['det']), x['url']))
    school_bytes.setdefault(x['s'], []).append(n)

for r in results:
    print(f"{r[0]:9} {r[3]} {str(r[4]):7} {str(r[5]):12} {r[2]:8} {r[1]}")

print('--- school byte variance (aggregate if identical) ---')
for s, lst in school_bytes.items():
    print(s, lst, 'same' if len(set(lst)) == 1 else 'varied')
