# -*- coding: utf-8 -*-
"""Round 184: 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": "berkeley-biostat-ma",
        "s": "berkeley",
        "n": "Biostatistics MA",
        "en": "MA in Biostatistics",
        "deg": "MA",
        "lvl": "m",
        "stem": 1,
        "dur": "2 years (4 semesters)",
        "ddl": "Fall: Dec 1 (year TBD)",
        "lang": "TOEFL iBT 90 / IELTS 7.0",
        "test": "GRE required but waivable (Calc 2 sem B+, LinAlg 1 sem B+, Stats 1 sem B+, GPA 3.0+)",
        "tui": "TBD",
        "url": "details/berkeley-biostat-ma.html",
        "school_cn": "UC Berkeley",
        "school_en": "UC Berkeley",
        "college": "School of Public Health - Division of Biostatistics",
        "website": "https://publichealth.berkeley.edu/academics/epidemiology-and-biostatistics/biostatistics-ma/",
        "overview": "Independent MA program in Biostatistics at Berkeley Public Health, co-taught by Statistics and Biostatistics faculty. Covers statistical inference, computational statistics, multivariate analysis, survival analysis, longitudinal data, causal inference, clinical trials, statistical genomics. Second year requires thesis or oral comprehensive exam.",
        "req": "Bachelor's in biomedical/biological sciences, math, stats or related; Calc + LinAlg recommended; GPA 3.0+; TOEFL 90 / IELTS 7.0; GRE waivable",
        "curriculum": "48 units: biostatistics & stats courses, public health courses, biology courses; thesis or oral comp exam in year 2; covers computational stats, multivariate, categorical data, survival, longitudinal, causal inference, clinical trials, genomic stats",
        "deadline": "Fall admission: Dec 1 (year TBD)",
        "funding": "TBD",
        "career": "Biostatistician, public health researcher, pharma stats analyst; PhD track in Biostatistics"
    },
    {
        "id": "usc-abe-ms",
        "s": "usc",
        "n": "Applied Biostatistics and Epidemiology MS",
        "en": "MS in Applied Biostatistics and Epidemiology",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "TBD (typically 2 years)",
        "ddl": "TBD (SOPHAS)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "GRE not required",
        "tui": "TBD",
        "url": "details/usc-abe-ms.html",
        "school_cn": "USC",
        "school_en": "University of Southern California",
        "college": "Keck School of Medicine - Population and Public Health Sciences",
        "website": "https://keck.usc.edu/applied-biostatistics-and-epidemiology-ms-program/",
        "overview": "Applied-oriented MS at Keck School of Medicine, integrating biostatistics and epidemiology methods for clinical research, public health, and pharma. Requires master's thesis and Practicum.",
        "req": "Bachelor's in allied health, pharmacology, public health, medicine, biological or clinical sciences; prerequisites: applied stats, college algebra, intro calculus, basic programming; GPA 3.0+; 3 letters of rec; SOPHAS application",
        "curriculum": "39 units: 26 core units + 9 elective units + 4 thesis units (PM 594a/b); Practicum required (0 units CR/NC); core covers biostatistics principles, data analysis, epi principles, experimental design, statistical methods",
        "deadline": "TBD (SOPHAS)",
        "funding": "TBD",
        "career": "Clinical research statistician, public health data analyst, pharma researcher; PhD track"
    },
    {
        "id": "notre-mscse",
        "s": "notre",
        "n": "Computer Science and Engineering MS",
        "en": "MS in Computer Science and Engineering (MSCSE)",
        "deg": "MSCSE",
        "lvl": "m",
        "stem": 1,
        "dur": "11 months (2 semesters + summer)",
        "ddl": "Fall: Dec 15; Spring: Oct 15",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "TBD",
        "tui": "TBD (TA positions available)",
        "url": "details/notre-mscse.html",
        "school_cn": "Notre Dame",
        "school_en": "University of Notre Dame",
        "college": "College of Engineering - Dept of Computer Science and Engineering",
        "website": "https://engineering.nd.edu/departments-programs/graduate-programs/ms-in-computer-science-and-engineering/",
        "overview": "Coursework-focused full-time MS at Notre Dame CSE, completable in 11 months. Covers AI, machine learning, algorithms/theory, computer architecture, computer vision, medical imaging, NLP, network & data science, cloud/HPC, security/crypto, software engineering, visualization, wireless/embedded. TTC bridge courses for non-CS backgrounds.",
        "req": "Bachelor's in CS or related field (non-CS can take TTC bridge); 3 letters of rec; Fall ddl Dec 15 / Spring ddl Oct 15; TA positions available (stipend)",
        "curriculum": "30 credits: 24 credits 60000-level courses + 6 credits research project or thesis; TTC bridge 12 credits (software design, data structures, computer systems, integrative practicum) not counted toward 30; tracks: AI/ML, CV, NLP, systems, security, HCI, theory",
        "deadline": "Fall: Dec 15; Spring: Oct 15",
        "funding": "TA positions available (stipend, availability depends on funding); other scholarships generally not provided",
        "career": "Tech industry, government, startup roles; PhD track"
    },
    {
        "id": "emory-cs-ms",
        "s": "emory",
        "n": "Computer Science MS",
        "en": "MS in Computer Science",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "2 years",
        "ddl": "TBD (typically Dec-Jan)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "TBD",
        "tui": "TBD",
        "url": "details/emory-cs-ms.html",
        "school_cn": "Emory",
        "school_en": "Emory University",
        "college": "Laney Graduate School - Dept of Computer Science",
        "website": "https://computerscience.emory.edu/graduate-ms/index.html",
        "overview": "Terminal MS in CS at Emory, interdisciplinary with medical school, Rollins Public Health, nursing, and CDC. Tracks: AI, ML, NLP, data mining, bio/health informatics, HPC, theory, systems. Practicum required (typically summer software engineering internship). Open to cross-disciplinary backgrounds.",
        "req": "Bachelor's in any field (must have programming + data structures/algorithms); recommended: linear algebra, discrete math, algorithms; at least one high-level language (Java/C/C++ preferred, Python acceptable but supplement with general-purpose language); Practicum required",
        "curriculum": "Core areas: algorithms, intelligent systems (ML/AI/NLP), data & info management, systems, security & privacy; electives; Practicum (real project or internship); tracks: Data Science / AI / HCI / Theory / Systems",
        "deadline": "TBD",
        "funding": "TBD",
        "career": "Industry CS engineer, data scientist, health informaticist; few continue to PhD"
    },
    {
        "id": "uva-msds",
        "s": "uva",
        "n": "Data Science MS (Residential)",
        "en": "MS in Data Science (Residential)",
        "deg": "MS",
        "lvl": "m",
        "stem": 1,
        "dur": "11 months (3 semesters) or 15 months (with internship)",
        "ddl": "Fall: TBD (typically Dec-Jan)",
        "lang": "TOEFL / IELTS (exact scores TBD)",
        "test": "TBD",
        "tui": "TBD",
        "url": "details/uva-msds.html",
        "school_cn": "UVA",
        "school_en": "University of Virginia",
        "college": "School of Data Science",
        "website": "https://datascience.virginia.edu/academics",
        "overview": "Full-time residential MS in Data Science at UVA, 11-month intensive curriculum. Spiral learning framework: languages/computation/linear modeling basics -> Bayesian ML, stats, data mining & text analytics, programming, data ethics. Choose Capstone or Internship as culminating experience. Interdisciplinary, open to all undergrad majors.",
        "req": "Bachelor's in any field; 4 prerequisites: Calculus II, Linear Algebra, Programming, Statistics (can be completed before matriculation); STEM program",
        "curriculum": "33 graded credits: 27 core credits + 6 elective credits; core covers programming, stats, ML, data mining, text analytics, deep learning, data ethics; culminating: Capstone project OR Internship (non-credit); 11 months (Fall+Spring+Summer) or 15 months (with Fall internship)",
        "deadline": "Fall admission: TBD",
        "funding": "TBD",
        "career": "Data scientist, ML engineer, data analyst; cross-industry (tech, healthcare, finance, government)"
    }
]

def make_detail(p):
    stem_label = "STEM" if p["stem"] else "Non-STEM"
    return 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>
* {{ margin:0; padding:0; box-sizing:border-box; }}
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>"""

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
j = bracket_start + 1
while j < len(html) and depth2 > 0:
    if html[j] == "[":
        depth2 += 1
    elif html[j] == "]":
        depth2 -= 1
    j += 1
vd_arr_end = j

new_vd = [f'"{p["url"]}"' for p in projects]
k = vd_arr_end - 2
while k >= 0 and html[k] in " \t\n\r":
    k -= 1
if html[k] == '"':
    vd_block = "," + ",".join(new_vd)
    html = html[:vd_arr_end-1] + vd_block + html[vd_arr_end-1:]
else:
    vd_block = ",".join(new_vd)
    html = html[:vd_arr_end-1] + vd_block + html[vd_arr_end-1:]

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

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

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