# -*- coding: utf-8 -*-
"""Round 186: batch add 5 programs"""
import re, os, sys
sys.stdout.reconfigure(encoding='utf-8')

BASE = r"D:\work buddy\2026-11-05-14-15-52"
IDX = os.path.join(BASE, "index_main.html")

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

projects = [
    {
        "id": "umich-msi",
        "s": "umich",
        "n": "Information MS",
        "en": "Master of Science in Information (MSI)",
        "deg": "MSI",
        "lvl": "m",
        "stem": 1,
        "dur": "2 years (full-time)",
        "ddl": "Fall: Dec 1 (year TBD)",
        "lang": "TOEFL 100+ recommended / IELTS",
        "test": "GRE not required",
        "tui": "TBD",
        "url": "details/umich-msi.html",
        "school_cn": "UMich",
        "school_en": "University of Michigan",
        "college": "School of Information (UMSI)",
        "website": "https://www.si.umich.edu/programs/degree-programs/master-science-information",
        "overview": "MS in Information (MSI) at UMSI, 48-credit degree with 5 pathways: Information and Data Analytics, Libraries/Archives/Knowledge Environments, Product Management, User-Centered Application Development, User Experience Research and Design. Interdisciplinary, no specific undergrad major required. Required internship (6 credits, up to 9). Mastery course or Master's Thesis option in second year.",
        "req": "Four-year bachelor's degree from accredited institution; no prerequisite courses; no coding experience required (Programming I is core); GRE not required; holistic review; typical GPA ~3.5; TOEFL 100+ recommended for non-native English",
        "curriculum": "48 credits total (min 39 from UMSI courses): first semester core (SI 500 Problem-Solving with People, Information and Technology; SI 506 Programming I); mastery prerequisite courses; SI 699 Mastery Course (project-based capstone) or 6-credit thesis; 9 credits free electives; 6 credits required internship (SI 690/681/688)",
        "deadline": "Fall admission: Dec 1 (year TBD)",
        "funding": "TBD",
        "career": "Data analyst, UX researcher, product manager, information architect, digital librarian; high career placement rate"
    },
    {
        "id": "duke-mids",
        "s": "duke",
        "n": "Interdisciplinary Data Science MS",
        "en": "MS in Interdisciplinary Data Science (MIDS)",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "2 years (4 semesters)",
        "ddl": "Fall: Dec 15 (year TBD)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE not required (holistic review)",
        "tui": "TBD",
        "url": "details/duke-mids.html",
        "school_cn": "Duke",
        "school_en": "Duke University",
        "college": "Master in Interdisciplinary Data Science (IDS Program)",
        "website": "https://datascience.duke.edu/",
        "overview": "MIDS at Duke, 42-credit interdisciplinary data science master's. 7 core courses covering statistical modeling, machine learning, NLP, data ethics, data visualization, data dialogues. Year-long Capstone Project with industry partners. Required summer internship between Year 1 and Year 2. Bootcamp in statistics, linear algebra, and programming before start.",
        "req": "Bachelor's degree from accredited institution; recommended quantitative coursework (linear algebra, statistics, Python); TOEFL/IELTS for non-native English; required summer internship for all students (F-1 students eligible for CPT)",
        "curriculum": "42 credits: 30 core IDS credits (Unifying Data Science, Principles of ML, Data Ethics, Data Logic/Visualization/Storytelling, NLP, Data Science Dialogues, MIDS Workshop) + 12 elective credits (at least 4 electives from ECE, Math, Stats, Energy & Public Policy, up to 6 allowed) + 3-credit Capstone (IDS 798, fall + spring of Year 2) + required summer internship",
        "deadline": "Fall admission: Dec 15 (year TBD)",
        "funding": "TBD",
        "career": "Data scientist, machine learning engineer, data analyst, policy analyst; industry-sponsored capstone projects"
    },
    {
        "id": "col-stat-ma",
        "s": "col",
        "n": "Statistics MA",
        "en": "MA in Statistics",
        "deg": "MA",
        "lvl": "m",
        "stem": 1,
        "dur": "3 semesters (full-time)",
        "ddl": "Fall: Dec 15 (year TBD)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE required (holistic review)",
        "tui": "TBD",
        "url": "details/col-stat-ma.html",
        "school_cn": "Columbia",
        "school_en": "Columbia University",
        "college": "Graduate School of Arts and Sciences (GSAS) - Department of Statistics",
        "website": "https://www.gsas.columbia.edu/content/statistics-ma",
        "overview": "MA in Statistics at Columbia GSAS, designed for students preparing for or working in positions that use statistics. Full-time and part-time options for domestic students; international students must be full-time. Most full-time students complete in 3 semesters. Required courses scheduled for early evening to accommodate working professionals. Covers probability theory, mathematical statistics, standard statistical methods, and practical experience with statistical software.",
        "req": "Bachelor's degree with strong quantitative preparation; thorough knowledge of calculus, linear algebra, and probability; TOEFL/IELTS for non-native English; GRE required",
        "curriculum": "4 required courses (basic probability theory, mathematical statistics, standard statistical methods) + 6+ elective courses; STAT GR5291 Advanced Data Analysis (capstone, project-based); electives include Applied Data Science (GR5243), Statistical Learning, Bayesian Statistics, etc.; most full-time students finish in 3 semesters",
        "deadline": "Fall admission: Dec 15 (year TBD)",
        "funding": "TBD",
        "career": "Statistician, data analyst, quantitative researcher in pharma, finance, insurance, market research, public health, government; also PhD preparatory track"
    },
    {
        "id": "cmu-mcds",
        "s": "cmu",
        "n": "Computational Data Science MS",
        "en": "Master of Computational Data Science (MCDS)",
        "deg": "MCDS",
        "lvl": "m",
        "stem": 1,
        "dur": "16 months (standard) or 20 months (extended with internship)",
        "ddl": "Fall: Dec 12 (year TBD)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE required (waived for CMU undergrads); QPA 3.0+",
        "tui": "TBD",
        "url": "details/cmu-mcds.html",
        "school_cn": "CMU",
        "school_en": "Carnegie Mellon University",
        "college": "School of Computer Science - Language Technologies Institute (LTI)",
        "website": "https://mcds.cs.cmu.edu/",
        "overview": "MCDS at CMU SCS/LTI, a 144-unit professional master's in computational data science. 5 core courses + concentration (Analytics, Systems, or Human-Centered Data Science) + Capstone project (industry-sponsored or faculty research). 16-month standard track (Dec graduation) or 20-month extended track (with summer internship, May graduation). Designed for CS/CE/related degree holders.",
        "req": "Bachelor's degree in CS, CE, or related field from highly ranked university; GPA 3.0+; GRE required (institution code 2074, dept 0402); TOEFL required for non-native English; 3 letters of recommendation; statement of purpose; resume; must pass 15-513 Intro to Computer Systems (summer before program)",
        "curriculum": "144 units: 5 core courses (63 units: Foundations of Computational Data Science, Cloud Computing, Machine Learning, Interactive Data Science, Data Science Seminar) + 3 concentration courses (36 units, choose Analytics/Systems/HCDS) + 3 Capstone courses (36 units: 11-634/635/632) + 1 SCS elective 600+ level (12 units); min 36 units/semester; QPA 3.0 required",
        "deadline": "Fall admission: Dec 12 (year TBD)",
        "funding": "TBD",
        "career": "Data scientist, machine learning engineer, big data engineer, NLP scientist; industry capstone projects; strong SCS alumni network"
    },
    {
        "id": "brown-scm-cs",
        "s": "brown",
        "n": "Computer Science ScM",
        "en": "ScM in Computer Science",
        "deg": "ScM",
        "lvl": "m",
        "stem": 1,
        "dur": "Up to 2 years",
        "ddl": "Fall: Jan 15; Spring: Nov 1",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE required (holistic review)",
        "tui": "TBD",
        "url": "details/brown-scm-cs.html",
        "school_cn": "Brown",
        "school_en": "Brown University",
        "college": "Department of Computer Science",
        "website": "https://cs.brown.edu/degrees/masters/",
        "overview": "ScM in Computer Science at Brown University, 8 graduate-level courses (6 Basic Component + 2 Advanced Component). Flexible curriculum: choose coursework option or research option (faculty-mentored project). Optional Professional Track with 140-840 hours of CS-related internship. Spring and Fall entry. Areas include AI/ML, robotics, security, software systems, theory, cryptography, socio-technical computing.",
        "req": "Bachelor's degree; foundational coursework in programming, algorithms, systems, mathematics, plus at least one advanced CS course; all courses 1000-level or higher with grade B or better; TOEFL/IELTS for non-native English; GRE required",
        "curriculum": "8 courses total: 6 Basic Component (no reading/research courses) + 2 Advanced Component (two 2000-level CS courses OR two semesters of CSCI 2980 master's project); optional Professional Track: add full-time CS internships totaling 140-840 hours (each internship min 140 hours) with reflective essay approved by DGS; Master's Contract approved by Program Advisor and DGS",
        "deadline": "Fall: Jan 15; Spring: Nov 1 (year TBD)",
        "funding": "TBD",
        "career": "Software engineer, ML researcher, security analyst, systems architect; PhD preparatory track; Professional Track option for career-focused students"
    },
]

def make_detail(p):
    stem_label = "STEM" if p["stem"] else "Non-STEM"
    html_tpl = f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{p['n']} - {p['school_en']}</title>
<style>
body {{ font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif; background:#f5f7fa; color:#333; line-height:1.7; }}
.container {{ max-width:960px; margin:0 auto; padding:20px; }}
.header {{ background:linear-gradient(135deg,#1a3a6b 0%,#2d5a9e 100%); color:#fff; padding:30px; border-radius:12px; margin-bottom:20px; }}
.header h1 {{ font-size:24px; margin-bottom:8px; }}
.header .school {{ font-size:16px; opacity:0.9; }}
.header .college {{ font-size:14px; opacity:0.75; margin-top:4px; }}
.badge {{ display:inline-block; background:rgba(255,255,255,0.2); padding:3px 12px; border-radius:20px; font-size:13px; margin-right:8px; margin-top:8px; }}
.cards {{ display:grid; grid-template-columns:1fr 1fr; gap:16px; }}
.card {{ background:#fff; border-radius:10px; padding:20px; box-shadow:0 2px 8px rgba(0,0,0,0.06); }}
.card h3 {{ font-size:16px; color:#1a3a6b; margin-bottom:12px; padding-bottom:8px; border-bottom:2px solid #e8eef5; }}
.card p, .card li {{ font-size:14px; color:#555; }}
.card ul {{ padding-left:20px; }}
.full {{ grid-column:1/-1; }}
.website {{ display:inline-block; background:#1a3a6b; color:#fff; padding:8px 16px; border-radius:6px; text-decoration:none; font-size:14px; margin-top:10px; }}
.website:hover {{ background:#2d5a9e; }}
</style>
</head>
<body>
<div class="container">
  <div class="header">
    <h1>{p['n']}</h1>
    <div class="school">{p['school_en']}</div>
    <div class="college">{p['college']}</div>
    <div>
      <span class="badge">{p['deg']}</span>
      <span class="badge">{stem_label}</span>
      <span class="badge">{p['dur']}</span>
    </div>
  </div>
  <div class="cards">
    <div class="card full">
      <h3>Overview</h3>
      <p>{p['overview']}</p>
      <a class="website" href="{p['website']}" target="_blank">Official Program Page</a>
    </div>
    <div class="card">
      <h3>Admissions Requirements</h3>
      <p>{p['req']}</p>
    </div>
    <div class="card">
      <h3>Curriculum</h3>
      <p>{p['curriculum']}</p>
    </div>
    <div class="card">
      <h3>Deadline</h3>
      <p>{p['deadline']}</p>
    </div>
    <div class="card">
      <h3>Language Requirements</h3>
      <p>{p['lang']}</p>
    </div>
    <div class="card">
      <h3>Test Requirements</h3>
      <p>{p['test']}</p>
    </div>
    <div class="card">
      <h3>Tuition & Funding</h3>
      <p>{p['tui']}</p>
      <p>{p['funding']}</p>
    </div>
    <div class="card full">
      <h3>Career Outcomes</h3>
      <p>{p['career']}</p>
    </div>
  </div>
</div>
</body>
</html>"""
    return html_tpl

for p in projects:
    path = os.path.join(BASE, p["url"])
    with open(path, "w", encoding="utf-8") as f:
        f.write(make_detail(p))
    print(f"Wrote: {p['url']}")

# Append PROGRAMS
prog_start = html.find("const PROGRAMS=[")
if prog_start == -1:
    prog_start = html.find("PROGRAMS=[")
bracket_start = html.find("[", prog_start)
depth = 1
i = bracket_start + 1
while i < len(html) and depth > 0:
    if html[i] == "[":
        depth += 1
    elif html[i] == "]":
        depth -= 1
    i += 1
prog_end = i

new_entries = []
for p in projects:
    entry = f'{{id:"{p["id"]}",s:"{p["s"]}",n:"{p["n"]}",en:"{p["en"]}",deg:"{p["deg"]}",lvl:"{p["lvl"]}",stem:{p["stem"]},dur:"{p["dur"]}",ddl:"{p["ddl"]}",lang:"{p["lang"]}",test:{{cls:"{p["test"]}"}},tui:"{p["tui"]}",url:"{p["url"]}"}}'
    new_entries.append(entry)

insert_pos = prog_end - 1
before = html[insert_pos-1]
if before == "]":
    new_block = ",".join(new_entries)
    html = html[:insert_pos] + new_block + html[insert_pos:]
else:
    j = insert_pos - 1
    while j >= 0 and html[j] in " \t\n\r":
        j -= 1
    if html[j] == "}":
        new_block = "," + ",".join(new_entries)
        html = html[:insert_pos] + new_block + html[insert_pos:]
    else:
        new_block = ",".join(new_entries)
        html = html[:insert_pos] + new_block + html[insert_pos:]

print(f"Appended {len(projects)} PROGRAMS entries")

# Append VD
vd_start = html.find("const VERIFIED_DETAILS=new Set(")
if vd_start == -1:
    vd_start = html.find("VERIFIED_DETAILS=new Set(")
paren_start = html.find("(", vd_start)
bracket_start = html.find("[", paren_start)
depth2 = 1
i = bracket_start + 1
while i < len(html) and depth2 > 0:
    if html[i] == "[":
        depth2 += 1
    elif html[i] == "]":
        depth2 -= 1
    i += 1
vd_end = i

vd_entries = [p["url"] for p in projects]
vd_block = ",".join(f'"{u}"' for u in vd_entries)

insert_pos = vd_end - 1
before = html[insert_pos-1]
if before == "[":
    new_block = vd_block
    html = html[:insert_pos] + new_block + html[insert_pos:]
else:
    j = insert_pos - 1
    while j >= 0 and html[j] in " \t\n\r":
        j -= 1
    if html[j] == '"':
        new_block = "," + vd_block
        html = html[:insert_pos] + new_block + html[insert_pos:]
    else:
        new_block = "," + vd_block
        html = html[:insert_pos] + new_block + html[insert_pos:]

print(f"Appended {len(vd_entries)} VD entries")

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

print(f"Done. File size: {len(html)}")
