# -*- coding: utf-8 -*-
"""第179轮：批量落库 4 条商学院 specialized master
1. umich-ross-macc  (Michigan Ross MAcc, 8 months, STEM, Fall start)
2. umich-ross-mscm  (Michigan Ross MSCM, 10 months, STEM, Summer start)
3. duke-mqm-ba      (Duke Fuqua MQM: Business Analytics, 10 months, STEM, July start)
4. usc-msmkt        (USC Marshall MSMKT, 1 year, Marketing Analytics track STEM, Fall start)
"""
import os, re, json

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

# ---------- 1. 写详情页 ----------
DETAILS = [
    {
        "file": "details/umich-ross-macc.html",
        "title": "密歇根大学安娜堡分校 | 会计硕士（Master of Accounting · 8 个月 · STEM · Ross）",
        "badge": "MAcc",
        "en": "Master of Accounting (MAcc, Ross School of Business)",
        "duration": "8 months full-time in-person (August–April; Fall + Winter terms)",
        "stem": "Yes (STEM-designated)",
        "ddl": "Fall term 入学（August start）；Paton Summer Immersion 路径 June start",
        "lang": "TOEFL iBT / IELTS Academic（具体分数待 Ross 系站确认）",
        "test": "GRE/GMAT 政策待 Ross 系站确认（Holistic review）",
        "tui": "学费待 Ross 系站确认",
        "url": "https://michiganross.umich.edu/graduate/master-of-accounting",
        "degree": "JHU Carey MAcc 是 STEM-designated full-time in-person，Ann Arbor 校区，8 个月紧凑制，August 开学（含一周 Washington DC EY Accounting and Public Policy Symposium）。",
        "core": [
            "Core (18 credits)：ACC 555 Corporate Financial Research and Reporting、ACC 561 Federal Taxation、ACC 601 Information Systems Design、ACC 630 Auditing & Assurance、ACC 695 EY Symposium",
            "Core Electives (3 credits)：ACC 564 Corporate Financial Reporting、ACC 618 Financial Communication & Investor Relations、ACC 620 Federal Taxation II、ACC 711/713 Financial Statement Analysis I/II 等",
            "Electives (9 credits)：corporate strategy, finance, marketing, international business, economics, public policy；可选 Law School tax courses",
            "可选 Accounting Analytics Concentration（bridge traditional accounting 与 analytics techniques）",
            "总 30 credits；满足 CPA 考试学分要求（most states）",
        ],
        "apply": [
            "在线 Application",
            "Bachelor's degree（无本科专业限制）",
            "Resume",
            "Essays",
            "本科成绩单",
            "推荐信",
            "GRE/GMAT（政策待确认）",
            "TOEFL/IELTS（国际生）",
        ],
        "prereq": [
            "Fall start 路径（5 门先修课）：Principles of Financial Accounting、Principles of Managerial Accounting、Intermediate Financial Accounting、Principles of Microeconomics、Statistics/Business Statistics",
            "Paton Summer Immersion 路径（3 门先修课）：Principles of Financial Accounting、Principles of Microeconomics、Statistics/Business Statistics（Managerial Accounting 与 Intermediate Financial Accounting 在项目内补）",
            "AP credit 可抵 Microeconomics 和 Statistics",
            "Finance courses、CPA exam scores、CPA licensure 不能抵 accounting prereq",
        ],
        "cost": [
            "学费待 Ross 系站确认（参考 MSCM out-of-state $67,510，MAcc 接近）",
            "所有学生自动考虑奖学金",
        ],
        "note": [
            "排除项：Ross MBA / EMBA 不在本库",
            "排除项：Ross 其他 part-time 项目不在本库",
            "录取分布，非最低门槛",
        ],
    },
    {
        "file": "details/umich-ross-mscm.html",
        "title": "密歇根大学安娜堡分校 | 供应链管理硕士（MS in Supply Chain Management · 10 个月 · STEM · Ross · QS 2026 全球 #1）",
        "badge": "MSCM",
        "en": "Master of Supply Chain Management (MSCM, Ross School of Business)",
        "duration": "10 months full-time in-person (June–April; Summer + Fall + Winter terms)",
        "stem": "Yes (STEM-designated)",
        "ddl": "Summer term 入学（June start）",
        "lang": "TOEFL iBT / IELTS Academic（具体分数待 Ross 系站确认）",
        "test": "GRE/GMAT 政策待 Ross 系站确认",
        "tui": "In-state $62,510 / Out-of-state $67,510（Cohort 2026–2027 学费，3 学期合计）",
        "url": "https://michiganross.umich.edu/graduate/master-of-supply-chain-management",
        "degree": "Michigan Ross MSCM 是 STEM-designated full-time in-person，Ann Arbor 校区，10 个月（June–April），QS 2026 全球供应链管理硕士排名 #1，Gartner 美国 #6。",
        "core": [
            "Summer：TO 505 Business Fundamentals Bootcamp、TO 736 Supply Chain Colloquium、Leadership & Career Training",
            "Fall：TO 605 Manufacturing & Supply Operations、TO 618 Applied Business Analytics、TO 624 Strategic Sourcing & Procurement Management、TO 616 Project Management、Electives",
            "Winter：TO 685 Supply Chain Consulting Studio（6 credits，真实企业项目 onsite）、TO 620 Global Supply Chain Management、TO 640 Big Data Management、TO 623 IT in Supply Chain & Logistics、TO 621 Logistics、Electives",
            "总 30 credits",
        ],
        "apply": [
            "在线 Application",
            "Bachelor's degree（无本科专业限制，无先修课要求）",
            "Resume",
            "Essays",
            "本科成绩单",
            "推荐信",
            "GRE/GMAT（政策待确认）",
            "TOEFL/IELTS（国际生）",
        ],
        "prereq": [
            "无先修课要求（官方明确 No prereq courses）",
            "面向 any undergraduate major（Class of 2027 来自 41 个本科背景，平均 GPA 3.57）",
        ],
        "cost": [
            "In-state $62,510 / Out-of-state $67,510（Summer $12,502/$13,502 + Fall $25,004/$27,004 + Winter $25,004/$27,004）",
            "Cohort 2027 学费将于 2027 年批准公布",
            "所有学生自动考虑奖学金",
        ],
        "note": [
            "排除项：Ross MBA / EMBA 不在本库",
            "Class of 2027：77 人，15 个国家，45% 女性，平均 GPA 3.57",
            "录取分布，非最低门槛",
        ],
    },
    {
        "file": "details/duke-mqm-ba.html",
        "title": "杜克大学 | 定量管理硕士：商业分析（MQM: Business Analytics · 10 个月 · STEM · Fuqua）",
        "badge": "MQM:BA",
        "en": "Master of Science in Quantitative Management: Business Analytics (MQM: BA, Fuqua School of Business)",
        "duration": "10 months full-time in-person (July–next May; 5 个 6-week terms)",
        "stem": "Yes (STEM-designated)",
        "ddl": "July 入学（每年 1 次）",
        "lang": "TOEFL iBT / IELTS Academic（具体分数待 Fuqua 系站确认）",
        "test": "GMAT/GRE required（Mid 80% GMAT 554–720；GRE Quant 159–170；GRE Verbal 150–166）",
        "tui": "学费待 Fuqua 系站确认",
        "url": "https://www.fuqua.duke.edu/programs/mqm-business-analytics",
        "degree": "Duke Fuqua MQM: Business Analytics 是 STEM-designated full-time in-person，Durham NC 校区，10 个月 cohort-based，面向 0–3 年工作经验的应届/初级毕业生，4 个 track：Finance / Marketing / Information Risk Management / Strategy。",
        "core": [
            "Term 1：data analytics 与 business fundamentals 核心课",
            "Terms 2–5：functional track（Finance / Marketing / Risk / Strategy）+ electives + Capstone Project",
            "最多 19 门课 + Capstone",
            "Elective options: 18 courses",
            "每门课每周 2 次，每次 2 小时 15 分钟",
        ],
        "apply": [
            "在线 Application",
            "Bachelor's degree",
            "Resume",
            "Essays",
            "本科成绩单",
            "推荐信",
            "GMAT/GRE（Mid 80% GMAT 554–720）",
            "TOEFL/IELTS（国际生）",
            "在申请时选择 functional track",
        ],
        "prereq": [
            "面向 college graduates with strong quantitative backgrounds",
            "Designed for 0–3 years post-college experience",
            "Average age 23，平均工作经验 24 个月",
        ],
        "cost": [
            "学费待 Fuqua 系站确认",
            "奖学金自动考虑",
        ],
        "note": [
            "排除项：Duke MBA / EMBA 不在本库",
            "排除项：Duke MMS: FOB 已在库（duke-mms-fob）",
            "排除项：Duke MQFE 2027 年不招生 → 排除",
            "Class of 2025：297 人，24 个国家，179 个本科院校，平均 GPA 3.57",
            "F-1 STEM 可享 36 个月 OPT（12 + 24）",
            "录取分布，非最低门槛",
        ],
    },
    {
        "file": "details/usc-msmkt.html",
        "title": "南加州大学 | 市场营销科学硕士（MS in Marketing · 1 年 · Marketing Analytics track STEM · Marshall）",
        "badge": "MSMKT",
        "en": "Master of Science in Marketing (MSMKT, Marshall School of Business)",
        "duration": "1 year full-time in-person (3 semesters: Fall + Spring + Fall; ~16 months)",
        "stem": "Marketing Analytics track 是 STEM-designated；Consumer Behavior track 非 STEM",
        "ddl": "Fall term 入学（only Fall start）",
        "lang": "TOEFL / IELTS（International applicants required）",
        "test": "GMAT/GRE not required",
        "tui": "学费待 Marshall 系站确认",
        "url": "https://www.marshall.usc.edu/programs/graduate-programs/specialized-masters/ms-marketing",
        "degree": "USC Marshall MSMKT 是 full-time in-person，Los Angeles 校区，1 年/3 semesters，两个 track：Consumer Behavior（非 STEM）和 Marketing Analytics（STEM-designated）。面向 business 和 non-business majors。",
        "core": [
            "总 33 units（13.5 required + 19.5 electives）",
            "Required：MKT 525 Consumer Behavior、MKT 556 Digital Marketing Strategy、MKT 566 Decision Making Using Marketing Analytics、GSBA 589 Practicum",
            "Consumer Behavior track：Fall 10.5 units core + Spring 3 units core",
            "Marketing Analytics track：Fall 9 units core + Spring 6 units core",
            "Electives：ACCT/BAEP/BUCO/DSO/FBE/GSBA/MKT/MOR/RISK 500-level courses",
            "Summer term 可选 internship",
        ],
        "apply": [
            "在线 Application（$175 application fee）",
            "Bachelor's degree from regionally accredited institution",
            "Official transcripts",
            "Resume",
            "Two Essays",
            "GMAT/GRE not required",
            "KIRA Video Interview（by invitation after application）",
            "TOEFL/IELTS（国际生）",
        ],
        "prereq": [
            "面向 business 和 non-business majors",
            "已在 USC 或其他学校修过 master's-level introductory marketing 课程的学生可申请替代（用 elective 替换重复 required course）",
        ],
        "cost": [
            "申请费 $175",
            "学费待 Marshall 系站确认",
            "奖学金自动考虑",
        ],
        "note": [
            "QS Business Masters Rankings 2025 市场营销 #3 全国",
            "排除项：USC MBA / EMBA 不在本库",
            "排除项：USC 在线/part-time 项目不在本库（本条目仅落 full-time in-person）",
            "排除项：USC MS in Global Supply Chain（已在库）",
            "录取分布，非最低门槛",
        ],
    },
]

HTML_TPL = """<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>{title}</title>
<style>
body{{font-family:-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;max-width:960px;margin:0 auto;padding:24px;color:#222;line-height:1.65;background:#fafafa}}
h1{{font-size:22px;border-bottom:3px solid #1a3a6c;padding-bottom:10px}}
h2{{font-size:16px;color:#1a3a6c;margin-top:28px;background:#eef2f8;padding:8px 12px;border-left:4px solid #1a3a6c}}
ul{{margin:8px 0;padding-left:22px}}
li{{margin:4px 0}}
.meta{{background:#fff;border:1px solid #dde;border-radius:6px;padding:12px 16px;margin:14px 0}}
.meta b{{color:#1a3a6c}}
a{{color:#1a6fc4}}
.badge{{display:inline-block;background:#1a3a6c;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;margin-left:8px}}
.warn{{background:#fff8e1;border-left:4px solid #f0a020;padding:8px 12px;margin:12px 0}}
</style>
</head>
<body>
<h1>{title} <span class="badge">{badge}</span></h1>
<div class="meta">
<b>英文名：</b>{en}<br>
<b>学制：</b>{duration}<br>
<b>STEM：</b>{stem}<br>
<b>申请截止：</b>{ddl}<br>
<b>语言要求：</b>{lang}<br>
<b>标化：</b>{test}<br>
<b>学费：</b>{tui}<br>
<b>官网：</b><a href="{url}" target="_blank">{url}</a>
</div>
<h2>学位与学制</h2><ul><li>{degree}</li></ul>
<h2>核心课程与学分</h2><ul>{core_html}</ul>
<h2>申请要求</h2><ul>{apply_html}</ul>
<h2>先修与背景</h2><ul>{prereq_html}</ul>
<h2>费用与资助</h2><ul>{cost_html}</ul>
<h2>录取提示</h2><ul>{note_html}</ul>
<div class="warn">说明：本页为半核验页，学位/学制/STEM状态/先修方向/标化分布已从学校官网核实；具体课程清单、精确学费、奖学金细节等待系站恢复后补全。录取分布，非最低门槛。</div>
</body>
</html>
"""

for d in DETAILS:
    html = HTML_TPL.format(
        title=d["title"], badge=d["badge"], en=d["en"], duration=d["duration"],
        stem=d["stem"], ddl=d["ddl"], lang=d["lang"], test=d["test"], tui=d["tui"],
        url=d["url"], degree=d["degree"],
        core_html="".join(f"<li>{x}</li>" for x in d["core"]),
        apply_html="".join(f"<li>{x}</li>" for x in d["apply"]),
        prereq_html="".join(f"<li>{x}</li>" for x in d["prereq"]),
        cost_html="".join(f"<li>{x}</li>" for x in d["cost"]),
        note_html="".join(f"<li>{x}</li>" for x in d["note"]),
    )
    with open(d["file"], "w", encoding="utf-8") as f:
        f.write(html)
    print(f"wrote {d['file']} ({len(html)} bytes)")

# ---------- 2. 追加 PROGRAMS + VD ----------
html = open("index_main.html", encoding="utf-8").read()

NEW_PROGRAMS = [
    # umich-ross-macc
    '{id:"umich-ross-macc",s:"umich",n:"会计硕士（Ross MAcc · 8 个月 · STEM）",en:"Master of Accounting (MAcc, Ross School of Business)",deg:"MAcc",lvl:"m",stem:1,dur:"8 months full-time in-person (August–April; Fall + Winter)",ddl:"Fall start (August); Paton Summer Immersion path June start",lang:"TOEFL iBT / IELTS Academic",test:{cls:"GRE/GMAT required (holistic review) — scores pending"},tui:"待补",url:"details/umich-ross-macc.html"},',
    # umich-ross-mscm
    '{id:"umich-ross-mscm",s:"umich",n:"供应链管理硕士（Ross MSCM · 10 个月 · STEM · QS 全球 #1）",en:"Master of Supply Chain Management (MSCM, Ross School of Business)",deg:"MSCM",lvl:"m",stem:1,dur:"10 months full-time in-person (June–April; Summer + Fall + Winter)",ddl:"Summer start (June)",lang:"TOEFL iBT / IELTS Academic",test:{cls:"GRE/GMAT required (holistic review) — scores pending"},tui:"In-state $62,510 / Out-of-state $67,510 (Cohort 2026-27)",url:"details/umich-ross-mscm.html"},',
    # duke-mqm-ba
    '{id:"duke-mqm-ba",s:"duke",n:"定量管理硕士：商业分析（MQM: BA · 10 个月 · STEM · 4 tracks）",en:"Master of Science in Quantitative Management: Business Analytics (MQM: BA, Fuqua School of Business)",deg:"MSQM",lvl:"m",stem:1,dur:"10 months full-time in-person (July–next May; 5 6-week terms)",ddl:"July start (annual)",lang:"TOEFL iBT / IELTS Academic",test:{cls:"GMAT/GRE required; Mid 80% GMAT 554-720, GRE Quant 159-170, GRE Verbal 150-166"},tui:"待补",url:"details/duke-mqm-ba.html"},',
    # usc-msmkt
    '{id:"usc-msmkt",s:"usc",n:"市场营销科学硕士（MS in Marketing · 1 年 · Marketing Analytics track STEM）",en:"Master of Science in Marketing (MSMKT, Marshall School of Business)",deg:"MSMKT",lvl:"m",stem:1,dur:"1 year full-time in-person (3 semesters: Fall + Spring + Fall; ~16 months)",ddl:"Fall start only",lang:"TOEFL / IELTS (international applicants)",test:{cls:"GMAT/GRE not required"},tui:"待补 (application fee $175)",url:"details/usc-msmkt.html"},',
]

NEW_VD = [
    "details/umich-ross-macc.html",
    "details/umich-ross-mscm.html",
    "details/duke-mqm-ba.html",
    "details/usc-msmkt.html",
]

# 定位 PROGRAMS 结束位置（括号深度匹配）
prog_start = html.index("const PROGRAMS=[")
depth = 0
i = prog_start + len("const PROGRAMS=")
for j in range(i, len(html)):
    if html[j] == '[':
        depth += 1
    elif html[j] == ']':
        depth -= 1
        if depth == 0:
            prog_end = j
            break

# 在 PROGRAMS 数组最后一条后追加
new_prog_block = "\n" + "\n".join(NEW_PROGRAMS)
html = html[:prog_end] + new_prog_block + "\n" + html[prog_end:]

# 定位 VD Set 结束位置（括号深度匹配）
vd_start = html.index("const VERIFIED_DETAILS=new Set(")
depth = 0
i = vd_start + len("const VERIFIED_DETAILS=new Set(")
for j in range(i, len(html)):
    if html[j] == '(':
        depth += 1
    elif html[j] == ')':
        depth -= 1
        if depth == 0:
            vd_end = j
            break

# 在 VD Set 最后一个元素后追加
vd_inner = html[i:vd_end]
# 找最后一个 " 的位置
last_quote = vd_inner.rstrip().rfind('"')
new_vd_block = ",\n" + ",\n".join(f'"{u}"' for u in NEW_VD)
html = html[:i + last_quote + 1] + new_vd_block + "\n" + html[i + last_quote + 1:]

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

print(f"\nindex_main.html written: {len(html)} chars")
print(f"PROGRAMS: +4, VD: +4")
