# -*- coding: utf-8 -*-
"""Round 185: 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-biostat-ms",
        "s": "umich",
        "n": "Biostatistics MS",
        "en": "Master of Science in Biostatistics",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "20 months (4 terms)",
        "ddl": "Fall: Dec 1 (year TBD)",
        "lang": "TOEFL / IELTS required for non-native English speakers",
        "test": "GRE not required (holistic review)",
        "tui": "TBD",
        "url": "details/umich-biostat-ms.html",
        "school_cn": "UMich",
        "school_en": "University of Michigan",
        "college": "School of Public Health - Department of Biostatistics",
        "website": "https://sph.umich.edu/biostat/programs/masters-biostat.html",
        "overview": "MS in Biostatistics at University of Michigan School of Public Health, designed for completion in 20 months (4 terms) with 48 credits. Training in statistical theory, biostatistical methods, data analysis, and computational statistics. Covers probability theory, statistical inference, linear regression, generalized linear models, survival analysis, longitudinal data, causal inference, and statistical computing.",
        "req": "Bachelor's degree from accredited institution; prerequisites: 3 semesters calculus (incl multivariable), 1 semester linear algebra, 1 semester intro statistics; students with less math prep may be conditionally admitted; 3 letters of recommendation; statement of purpose + personal statement; TOEFL/IELTS for non-native English",
        "curriculum": "48 credits total: core biostatistics sequence (probability, inference, applied stats I/II, GLMs), 12+ elective credits in Biostatistics 600/800 level or Statistics 500/600 level; optional thesis; recommended advanced calculus/real analysis and computing (R/Python/C++)",
        "deadline": "Fall admission: Dec 1 (year TBD)",
        "funding": "TBD",
        "career": "Biostatistician in pharma, public health, government, or industry; PhD track in Biostatistics"
    },
    {
        "id": "umich-hds-ms",
        "s": "umich",
        "n": "Health Data Science MS",
        "en": "Master of Science in Health Data Science",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "20 months (4 terms)",
        "ddl": "Fall: Dec 1 (year TBD)",
        "lang": "TOEFL / IELTS required for non-native English speakers",
        "test": "GRE not required (holistic review)",
        "tui": "TBD",
        "url": "details/umich-hds-ms.html",
        "school_cn": "UMich",
        "school_en": "University of Michigan",
        "college": "School of Public Health - Department of Biostatistics",
        "website": "https://sph.umich.edu/biostat/programs/masters-hds.html",
        "overview": "MS in Health Data Science, a new program launched Fall 2023 by the Department of Biostatistics. Designed for completion in 20 months with 48 credits. Focus on health data analytics, statistical computing, machine learning for health, and practical workforce training. More flexible and inclusive than the traditional Biostatistics MS, with a required computing module (R, Python, C++).",
        "req": "Bachelor's degree from accredited institution; prerequisites: 3 semesters calculus (incl multivariable), 1 semester linear algebra, 1 semester intro statistics; students with less math prep may be conditionally admitted; 3 letters of recommendation; statement of purpose + personal statement; TOEFL/IELTS for non-native English",
        "curriculum": "48 credits: core biostatistics sequence + required computing course (BIOSTAT 607: R, Python, C++ modules, 3 credits, waivable by exam or prior coursework) + electives; practical workforce training in health data analytics",
        "deadline": "Fall admission: Dec 1 (year TBD)",
        "funding": "TBD",
        "career": "Health data analyst, clinical data scientist, biostatistics programmer, pharma data scientist; industry-focused professional degree"
    },
    {
        "id": "brown-scm-biostat",
        "s": "brown",
        "n": "Biostatistics ScM",
        "en": "ScM in Biostatistics",
        "deg": "ScM",
        "lvl": "m",
        "stem": 1,
        "dur": "2 years (full-time)",
        "ddl": "Fall: Dec 15 (year TBD)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE not required (holistic review)",
        "tui": "TBD",
        "url": "details/brown-scm-biostat.html",
        "school_cn": "Brown",
        "school_en": "Brown University",
        "college": "School of Public Health - Department of Biostatistics",
        "website": "https://biostatistics.sph.brown.edu/academics/masters-programs/scm",
        "overview": "ScM in Biostatistics at Brown University School of Public Health. Requires 10 courses (7 required + 3 elective) plus a mandatory thesis or project. Training in statistical inference, generalized linear models, longitudinal data, multilevel models, causal inference, statistical learning, and R programming. Designed for careers as statisticians and data analysts in industry, government, or academia.",
        "req": "Entering students assumed to have: 1 semester multivariate calculus, 1 semester linear algebra, 1 semester mathematical probability (using calculus); recommended 3 semesters calculus; thesis or project required; TOEFL/IELTS for non-native English",
        "curriculum": "10 courses total: 7 required biostatistics courses (probability & inference, applied GLMs, longitudinal models, multilevel models, practical data analysis, statistical programming with R, causal inference & missing data, statistical learning/big data) + 3 electives + mandatory PHP 2000 Foundations of Public Health (online, non-credit); sequence configured 3-3-2-2",
        "deadline": "Fall admission: Dec 15 (year TBD)",
        "funding": "TBD",
        "career": "Biostatistician, data analyst, statistical programmer in industry, government, or pharma; PhD track in Biostatistics"
    },
    {
        "id": "gatech-msbinf",
        "s": "gatech",
        "n": "Bioinformatics MS",
        "en": "Master of Science in Bioinformatics",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "3 semesters (professional master's)",
        "ddl": "Fall: Feb 1 (year TBD)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE not required (holistic review)",
        "tui": "TBD",
        "url": "details/gatech-msbinf.html",
        "school_cn": "Georgia Tech",
        "school_en": "Georgia Institute of Technology",
        "college": "College of Sciences - School of Biological Sciences / College of Computing",
        "website": "https://catalog.gatech.edu/programs/bioinformatics-ms/",
        "overview": "Professional MS in Bioinformatics at Georgia Tech, a three-semester focused program combining 36 credit hours of computer science, biology, statistics, and bioinformatics coursework. No thesis required; virtually all students perform research with faculty or professional internships/co-ops. Interdisciplinary program bridging biology, CS, and statistics.",
        "req": "Bachelor's degree in related field (biology, CS, math, stats, engineering); strong quantitative background; international students must register with Cooperative Education office to work off-campus; TOEFL/IELTS for non-native English",
        "curriculum": "36 credits total: 21 core hours (BIOL 6150 Genomics & Applied Bioinformatics, BIOL 7200 Programming for Bioinformatics, BIOL 7210 Computational Genomics, CS 4400 Database Systems, CX 4803 Machine Learning in Computational Biology, Statistics requirement) + 15 elective hours + Capstone (3 credits, e.g. BIOL 8530 Human Evolutionary Genomics or CSE 6242 Data & Visual Analytics)",
        "deadline": "Fall admission: Feb 1 (year TBD)",
        "funding": "GRA awards available for MS BINF students; research opportunities with faculty",
        "career": "Bioinformatics scientist, computational biologist, genomics analyst, pharma data scientist; PhD track in Bioinformatics/Computational Biology"
    },
    {
        "id": "cmu-mspm",
        "s": "cmu",
        "n": "Product Management MS",
        "en": "MS in Product Management (MSPM)",
        "deg": "MS",
        "lvl": "m",
        "stem": 0,
        "dur": "12 months (Jan start, 3 semesters)",
        "ddl": "Round deadlines: July 1 for Fall (year TBD)",
        "lang": "TOEFL / IELTS / Duolingo accepted",
        "test": "GMAT / GRE required (waiver available)",
        "tui": "TBD",
        "url": "details/cmu-mspm.html",
        "school_cn": "CMU",
        "school_en": "Carnegie Mellon University",
        "college": "Tepper School of Business + HCII (School of Computer Science)",
        "website": "https://www.cmu.edu/tepper/programs/master-product-management/",
        "overview": "MS in Product Management (MSPM) at Carnegie Mellon University, a joint program of Tepper School of Business and the Human-Computer Interaction Institute (HCII) in the School of Computer Science. One-year program starting in January, designed for early-career professionals with technical background. Integrates business fundamentals, HCI/design, data science, and leadership for tech product managers. Includes summer internship and fall capstone project.",
        "req": "Four-year undergraduate degree in CS, SE, CE or related technical field; competency in calculus, linear algebra, basic statistics, and basic programming; at least 1 year of work experience preferred; 2 professional recommendations; essays; GMAT/GRE with waiver available; TOEFL/IELTS/Duolingo for non-native English; $125 application fee",
        "curriculum": "Spring semester (Jan-May): Business Fundamentals for High Tech PM, Principles of Product Management I/II, Product Marketing, Managing People and Teams, Business Presentations, Data Science for PM, HCI for PM, core design course (Digital Service Innovation / Service Design / AI Products); Summer: MSPM Internship; Fall semester (Aug-Dec): Capstone Project, Technical Depth Elective (SCS), Tepper elective; total ~120 units",
        "deadline": "July 1 (first round for January start; year TBD)",
        "funding": "TBD",
        "career": "Product Manager, Senior Product Analyst, Product Strategy Lead at tech companies; Accelerate Leadership Center executive coaching"
    },
]

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)}")
