import os, re
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")

PROGS = [
    {
        "id":"nyu-mpa-hpam",
        "s":"nyu",
        "n":"健康政策与管理公共管理硕士",
        "en":"MPA in Health Policy and Management",
        "deg":"MPA",
        "lvl":"m",
        "stem":"0",
        "dur":"45 credits; full-time 2 years / part-time 3-4 years; Fall & Spring entry",
        "ddl":"Fall 2027: May 10, 2027 (priority/scholarship earlier; rolling thereafter)",
        "lang":"TOEFL 100 / IELTS 7.0 required if bachelor's not taught in English",
        "test_cls":"GRE or GMAT optional (holistic review; no minimum score)",
        "tui":"~$98,741 total estimated (2-year full-time; includes tuition + registration/service fees per Wagner 2026-27)",
        "url":"details/nyu-mpa-hpam.html",
        "website":"https://wagner.nyu.edu/health-degrees",
        "summary":"NYU Wagner MPA in Health Policy & Management (HPAM). An in-person 45-credit MPA preparing professionals for federal/state health agencies, for-profit and nonprofit healthcare, consulting, research institutes, international organizations, and public health advocacy. Fall and Spring entry; full-time students can complete in as little as 2 years. Distinct from NYU Wagner Online MHA (28 months online, excluded).",
        "reqs":[
            "Online application via NYU Wagner",
            "Essays",
            "Résumé / CV",
            "Two (2) letters of recommendation",
            "Transcripts",
            "GRE or GMAT optional (no minimum)",
            "Video essay optional",
            "TOEFL 100 / IELTS 7.0 if bachelor's not English-medium",
            "International credential evaluation required for degrees outside US/Canada",
            "$85 application fee"
        ]
    },
    {
        "id":"nyu-mpa-pnp",
        "s":"nyu",
        "n":"公共与非营利管理与政策公共管理硕士",
        "en":"MPA in Public and Nonprofit Management and Policy",
        "deg":"MPA",
        "lvl":"m",
        "stem":"0",
        "dur":"45 credits; full-time 2 years / part-time 3-4 years; Fall & Spring entry",
        "ddl":"Early Action / Fellowship priority (Nov 2026); Round 2 (Feb 2027); Final rolling thereafter",
        "lang":"TOEFL / IELTS required if bachelor's not taught in English",
        "test_cls":"GRE or GMAT optional (holistic review; no minimum score)",
        "tui":"Per-credit Wagner tuition (see NYU Bursar for 2027-28 rate)",
        "url":"details/nyu-mpa-pnp.html",
        "website":"https://wagner.nyu.edu/education/degrees/mpa-public-nonprofit-management-policy",
        "summary":"NYU Wagner MPA in Public and Nonprofit Management and Policy (MPA-PNP). 45-credit in-person MPA with interdisciplinary coursework in finance, policy, and management. Specializations: Finance, International Development, Public Policy Analysis, Social Innovation. NASPAA-accredited. Full-time 2 years or part-time 3-4 years; students may switch between full-time and part-time.",
        "reqs":[
            "Online application via NYU Wagner",
            "Essays",
            "Résumé / CV",
            "Letters of recommendation",
            "Transcripts",
            "GRE or GMAT optional (no minimum)",
            "TOEFL / IELTS if bachelor's not English-medium",
            "Year-long Capstone project (Fall + Spring)",
            "Spring entrants typically take 2.5 years due to Capstone sequencing"
        ]
    },
    {
        "id":"nyu-physics-ms",
        "s":"nyu",
        "n":"物理学硕士",
        "en":"Master of Science in Physics",
        "deg":"MS",
        "lvl":"m",
        "stem":"1",
        "dur":"32 points credit; Fall only (no Spring entry)",
        "ddl":"December 30, 5PM ET (Fall admission)",
        "lang":"TOEFL / IELTS required (waiver for English-medium degree, US citizen/PR, or native speaker)",
        "test_cls":"GRE General NOT required (do not send); GRE Physics Subject Test NOT reviewed",
        "tui":"Per-point GSAS tuition (see NYU Bursar for 2027-28 rate)",
        "url":"details/nyu-physics-ms.html",
        "website":"https://gsas.nyu.edu/academics/bulletin/physics/ms-physics.html",
        "summary":"NYU GSAS Department of Physics MS. 32 points credit (≥24 in residence, ≥20 in Physics), GPA ≥ B (3.0). Must pass at least 5 of 6 core courses: Statistical Mechanics, Electromagnetism, Computational Physics, Classical & Quantum Mechanics I & II, Experimental Physics. Three completion options: Option A (Report), Option B (Thesis), Option C (Examination). MS students generally self-fund via federal aid/loans/external awards.",
        "reqs":[
            "Online application via NYU GSAS",
            "Academic transcripts",
            "Applicant statements (Statement of Purpose)",
            "Résumé / CV",
            "Letters of recommendation",
            "Non-refundable application fee",
            "TOEFL / IELTS (waiver for English-medium degree, US citizen/PR, or native English speaker)",
            "Do NOT send GRE scores; they will not be reviewed",
            "Fall admission only; no Spring entry"
        ]
    },
    {
        "id":"ut-nmc-ma",
        "s":"ut",
        "n":"近东与中东文明文学硕士",
        "en":"Master of Arts in Near and Middle Eastern Civilizations",
        "deg":"MA",
        "lvl":"m",
        "stem":"0",
        "dur":"2 years full-time; Fall entry only",
        "ddl":"November 30 (application fee payment); December 8 (supporting documents and reference letters)",
        "lang":"TOEFL / IELTS / Duolingo required (see SGS General Regulations 4.3)",
        "test_cls":"No GRE required",
        "tui":"Per-session SGS tuition; see UofT Feen for 2027-28 rate",
        "url":"details/ut-nmc-ma.html",
        "website":"https://www.nmc.utoronto.ca/graduate/prospective-graduate-students/application-information",
        "summary":"University of Toronto Department of Near & Middle Eastern Civilizations (NMC) MA. Research-oriented MA in the humanistic study of the Near and Middle East (Ancient Near East, Middle Eastern and Islamic Studies, Islamic Art and Material Culture). CGS-Master's eligible for Canadian citizens/permanent residents. Research language requirements (Arabic, Persian, Turkish, Hebrew, or French/German) vary by concentration.",
        "reqs":[
            "4-year bachelor's degree in a relevant program with minimum B+ average in final year",
            "Two (2) letters of reference (institutional email preferred)",
            "Statement of academic intent",
            "Appropriate knowledge of a primary source language (Arabic/Persian/Turkish/Hebrew) and/or European scholarship languages",
            "Islamic Art and Material Culture concentration: reading knowledge of French or German at admission",
            "TOEFL / IELTS / Duolingo (see SGS General Regulations 4.3)",
            "Application fee paid by November 30; all supporting docs by December 8",
            "CGS-M application deadline December 1 (for Canadian citizens/PRs)"
        ]
    },
    {
        "id":"up-ealc-ma",
        "s":"up",
        "n":"东亚语言与文明文学硕士",
        "en":"Master of Arts in East Asian Languages and Civilizations",
        "deg":"MA",
        "lvl":"m",
        "stem":"0",
        "dur":"8 course units; 1-2 years (1 year if pass language exam on admission); part-time allowed",
        "ddl":"February 1, 2027, 11:59PM ET (Fall admission)",
        "lang":"TOEFL required for non-native English speakers",
        "test_cls":"GRE NOT required (no minimum; applicants need not submit scores)",
        "tui":"Per-credit SAS tuition (see Penn Bursar for 2027-28 rate); no MA funding (PhD fully funded)",
        "url":"details/up-ealc-ma.html",
        "website":"https://www.sas.upenn.edu/graduate-division/prospective-students",
        "summary":"Penn SAS Graduate Group in East Asian Languages and Civilizations (EALC) MA. 8 course units (5000 level or above), covering literature, history, philosophy, religion, art, and archaeology of China, Japan, Korea, and Mongolia. Strong classical language training (Classical Chinese, Japanese, Korean, Mongolian). Can be combined with another Penn MA or taken part-time. No funding for MA students (PhD admits fully funded for 5 years).",
        "reqs":[
            "Online application opens October 1, 2026 for Fall 2027",
            "Unofficial transcripts; official upon admission",
            "Three (3) letters of recommendation",
            "Statement of purpose",
            "Writing sample (strongly recommended for humanities)",
            "Résumé / CV",
            "TOEFL for non-native English speakers",
            "GRE not required",
            "Undergraduate preparation: minimum 6 semesters of primary East Asian language plus literature/history/religion coursework; second East Asian language preferred",
            "$90 application fee; limited need-based waivers"
        ]
    }
]

TEMPLATE = """<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>{n} | {s_upper}</title>
<style>
body{{font-family:-apple-system,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;max-width:980px;margin:24px auto;padding:0 20px;color:#222;line-height:1.65;background:#fafafa}}
h1{{font-size:24px;border-bottom:3px solid #8b1a1a;padding-bottom:8px;margin-bottom:4px}}
.sub{{color:#666;margin-bottom:20px;font-size:14px}}
.grid{{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin:18px 0}}
.card{{background:#fff;border:1px solid #e3e3e3;border-radius:8px;padding:14px 16px;box-shadow:0 1px 2px rgba(0,0,0,0.03)}}
.card h3{{margin:0 0 8px;font-size:15px;color:#8b1a1a;border-bottom:1px solid #f0d6d6;padding-bottom:6px}}
.card p,.card li{{font-size:14px;margin:4px 0}}
.kv{{display:flex;justify-content:space-between;padding:3px 0;font-size:14px}}
.kv b{{color:#444}}
a{{color:#8b1a1a}}
.flag{{display:inline-block;background:#fff4e5;color:#b45309;padding:2px 8px;border-radius:10px;font-size:12px;margin-left:6px}}
ul{{padding-left:20px;margin:6px 0}}
</style>
</head>
<body>
<h1>{n}</h1>
<div class="sub">{en} · {s_upper} · {deg}<span class="flag">半核验页 · 课程/学分/材料清单待补</span></div>
<div class="grid">
  <div class="card"><h3>项目概览</h3><p>{summary}</p></div>
  <div class="card"><h3>关键参数</h3>
    <div class="kv"><b>学位</b><span>{deg}</span></div>
    <div class="kv"><b>层级</b><span>{lvl_cn}</span></div>
    <div class="kv"><b>STEM</b><span>{stem_cn}</span></div>
    <div class="kv"><b>学制</b><span>{dur}</span></div>
    <div class="kv"><b>申请截止</b><span>{ddl}</span></div>
    <div class="kv"><b>语言要求</b><span>{lang}</span></div>
    <div class="kv"><b>标化</b><span>{test_cls}</span></div>
    <div class="kv"><b>学费</b><span>{tui}</span></div>
  </div>
  <div class="card"><h3>申请材料 / 要求</h3><ul>{req_html}</ul></div>
  <div class="card"><h3>官方来源</h3>
    <p>学校官网：<a href="{website}" target="_blank">{website}</a></p>
    <p>本页为半核验页，课程设置、精确学分、完整材料清单字段待后续补核。</p>
    <p>录取分数若官方公布，仅作"录取分布，非最低门槛"参考。</p>
  </div>
</div>
</body>
</html>
"""

def lvl_cn(v): return "硕士" if v=="m" else "博士"
def stem_cn(v): return "STEM 认证" if v=="1" else "非 STEM"

for p in PROGS:
    req_html = "".join(f"<li>{r}</li>" for r in p["reqs"])
    html = TEMPLATE.format(
        n=p["n"], s_upper=p["s"].upper(), en=p["en"], deg=p["deg"],
        summary=p["summary"], dur=p["dur"], ddl=p["ddl"], lang=p["lang"],
        test_cls=p["test_cls"], tui=p["tui"],
        lvl_cn=lvl_cn(p["lvl"]), stem_cn=stem_cn(p["stem"]),
        req_html=req_html, website=p["website"]
    )
    open(p["url"],"w",encoding="utf-8").write(html)
    print("Wrote:", p["url"])

PROGRAMS_BLOCK = []
for p in PROGS:
    PROGRAMS_BLOCK.append(
        '{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:"{stem}",dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test_cls}"}},tui:"{tui}",url:"{url}"}}'.format(**p)
    )

with open("index_main.html","r",encoding="utf-8") as f:
    html = f.read()

m = re.search(r"const PROGRAMS\s*=\s*\[", html)
assert m, "PROGRAMS array not found"
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == "[": depth += 1
    elif c == "]": depth -= 1
    i += 1
prog_end = i - 1
before = html[:prog_end].rstrip()
if not before.endswith("[") and not before.endswith(","):
    before += ","
insert_text = "\n" + ",".join(PROGRAMS_BLOCK) + "\n"
html = before + insert_text + html[prog_end:]

m2 = re.search(r"const VERIFIED_DETAILS\s*=\s*new Set\(", html)
assert m2, "VERIFIED_DETAILS not found"
start2 = m2.end()
depth = 1
i = start2
while i < len(html) and depth > 0:
    c = html[i]
    if c == "(": depth += 1
    elif c == ")": depth -= 1
    i += 1
vd_end = i - 1
bracket_pos = html.rfind("]", start2, vd_end)
assert bracket_pos > 0, "VD array close not found"
before_vd = html[:bracket_pos].rstrip()
if not before_vd.endswith("[") and not before_vd.endswith(","):
    before_vd += ","
vd_entries = ",".join(f'"{p["url"]}"' for p in PROGS)
html = before_vd + "\n" + vd_entries + "\n" + html[bracket_pos:]

with open("index_main.html","w",encoding="utf-8") as f:
    f.write(html)
print(f"Appended {len(PROGS)} PROGRAMS entries and {len(PROGS)} VD entries")
print("Done. File size:", len(html))
