# -*- coding: utf-8 -*-
"""Round 240: batch add 5 (4 Chemical Engineering PhD + UBC Botany PhD)
- MIT ChemE PhD (Dec 1, GRE not required/accepted for PhD/ScD/MSCEP; TOEFL 100/IELTS 7.0/DET 135)
- Berkeley CBE PhD (Dec 1, GRE not considered explicitly; 18 units letter-graded; ChE 375 Pedagogy)
- UCSD CENG PhD (Dec 9, GRE REQUIRED - exception to trend; TOEFL 85/IELTS 7.0; GPA 3.0)
- UMich ChemE PhD (Dec 1, GRE not required; typical GPA 3.6, TOEFL 109/IELTS 7.0)
- UBC Botany PhD (Jan 10, 2027, supervisor must be confirmed before application; Canadian cycle)
"""
import os, re

BASE = os.path.dirname(os.path.abspath(__file__))
DET = os.path.join(BASE, "details")
os.makedirs(DET, exist_ok=True)

PROGRAMS = [
    {
        "id": "mit-cheme-phd",
        "s": "mit",
        "n": "化学工程博士",
        "en": "PhD in Chemical Engineering (Massachusetts Institute of Technology, MIT School of Engineering, Department of Chemical Engineering; doctor of philosophy / doctor of science; no separate MS terminal track)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years full-time residential; fall-only (September entry); single admission process for PhD and MSCEP (master's track); research advisor assignment by end of first year; thesis proposal, general exam, thesis defense; January interview weekend for invited PhD candidates",
        "ddl": "Fall 2027 (September): application opens September 15, 2026. **Deadline December 1, 2026 at 23:59 EST**. Application fee $90. PhD candidates invited to interview with ChemE admissions committee in January; decisions rolling January-March; visit weekend March; April 15 CGS reply.",
        "lang": "TOEFL iBT minimum 100 / IELTS Academic 7.0 / Duolingo DET 135 / Cambridge English Exam; ETS MIT code 3514; English-medium undergraduate exempts; scores within 5 years.",
        "test": {"cls": "GRE NOT REQUIRED/ACCEPTED (MIT ChemE: 'ChemE does not accept GRE scores and will not consider GRE scores in the evaluation of MSCEP and PhD applications.' Exception: PhDCEP (program with Sloan) self-reported GRE is recommended. 3 LOR; SOP; CV/resume (max 2 pages, 12pt font, 1 inch margins); scanned transcripts; background in chemistry, biology, physics, mathematics, and computer science relevant to field of interest)."},
        "tui": "Full funding for admitted PhD students through research/teaching assistantships and MIT fellowships (tuition + stipend + health insurance). Application fee $90. Fall-only admission.",
        "url": "details/mit-cheme-phd.html",
    },
    {
        "id": "berkeley-cbe-phd",
        "s": "berkeley",
        "n": "化学与生物分子工程博士",
        "en": "PhD in Chemical and Biomolecular Engineering (University of California Berkeley, College of Chemistry, Department of Chemical and Biomolecular Engineering, CBE; no terminal research MS offered - PDP professional MS is separate)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years full-time residential; fall-only; 18 units of letter-graded coursework (9 units minimum from five core courses: math, thermodynamics, reaction engineering, transport phenomena); ChE 375 Pedagogy course required; department colloquium; two departmental exams; thesis research from second semester; designated emphasis (DE) options available",
        "ddl": "Fall 2027 (August): online application opens September 2026. **Deadline December 1, 2026 at 8:59 PM Pacific Time**. Fall admission only; no Spring or Summer admission. Decisions typically by early March.",
        "lang": "TOEFL iBT minimum 90 / IELTS Academic 7.0 (Berkeley Graduate Division minimum); ETS Berkeley code 4833; English-medium undergraduate may be exempted; scores within 2 years.",
        "test": {"cls": "GRE NOT CONSIDERED (Berkeley CBE: 'The faculty of the Department of Chemical and Biomolecular Engineering (CBE) at UC Berkeley have determined the Graduate Records Exam (GRE) is a proven identifier of race and socio-economic status... CBE will no longer consider it for admission.' Subject tests also not required. 3 LOR; Statement of Purpose; Personal History Statement; transcripts; no master's required to apply for doctorate; typical undergraduate in chemical engineering)."},
        "tui": "CBE PhD students typically receive full funding through departmental research/teaching assistantships and fellowships (tuition + stipend + health insurance). MS research track currently paused for admissions; PDP professional MS is separate.",
        "url": "details/berkeley-cbe-phd.html",
    },
    {
        "id": "ucsd-ceng-phd",
        "s": "ucsd",
        "n": "化学工程博士",
        "en": "PhD in Chemical Engineering (University of California San Diego, Aiiso Yufeng Li Family Department of Chemical and Nano Engineering; includes PhD in Chemical Engineering with specialization in Multi-scale Biology)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5 years full-time residential; fall-only (September); 36+ units of graduate coursework; Preliminary Qualifying Examination; dissertation research and defense; direct entry from BS to PhD allowed; MS may be earned en route",
        "ddl": "Fall 2027 (September): application opens September 2, 2026. **PhD deadline December 9, 2026**. MS deadline July 14, 2027 (rolling). Fall admission only; no Winter or Spring. Decisions typically by early March.",
        "lang": "TOEFL iBT minimum 85 / IELTS Academic 7.0 / PTE Academic 65 / Duolingo DET 120 (UCSD minimum); ETS UCSD code 4836; English-medium undergraduate may be exempted; scores within 2 years.",
        "test": {"cls": "GRE REQUIRED FOR PHD (UCSD CENG: 'For Fall 2027 admissions, submission of GRE scores is optional for MS candidates but mandatory for PhD candidates.' Note: this is an exception to the broader engineering PhD trend toward GRE-free. 3 LOR; SOP; CV; transcripts; minimum GPA 3.0/4.0 (typical admitted higher); BS in chemical engineering or related engineering/science/math)."},
        "tui": "CENG PhD students typically receive full funding through departmental research/teaching assistantships and fellowships (tuition + stipend + health insurance). Minimum GPA 3.0; typical admitted GPA higher. Fall-only admission.",
        "url": "details/ucsd-ceng-phd.html",
    },
    {
        "id": "umich-che-phd",
        "s": "umich",
        "n": "化学工程博士",
        "en": "PhD in Chemical Engineering (University of Michigan Ann Arbor, Rackham Graduate School, Department of Chemical Engineering; direct entry from BS to PhD allowed; MS not required)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4-5 years full-time residential; fall primary (September); winter (January) limited; direct BS-to-PhD entry; MS-on-way option; thesis research; qualifying exam; dissertation defense; typically 5 years for direct BS entry",
        "ddl": "Fall 2027 (September): **PhD deadline December 1, 2026**. MS deadline January 15, 2027. Winter term (January): deadline October 1 (rarely admitted). Decisions rolling January-March for PhD; February-March for MS; April 15 CGS reply.",
        "lang": "TOEFL iBT minimum 100 / IELTS Academic 7.0; ETS UMich Rackham code 1839; English-medium undergraduate exempts; typical admitted PhD: TOEFL 109 (iBT) / IELTS 7.0; scores within 2 years.",
        "test": {"cls": "GRE NOT REQUIRED (UMich ChemE: 'GRE scores are no longer required.' Contacting individual faculty does not influence admissions decision. 3 LOR (prefer professors and research advisors); SOP; transcripts; typical admitted PhD GPA 3.6/4.0; BS in chemical engineering or related engineering/science)."},
        "tui": "PhD students typically receive full funding through Rackham/Rackham-funded departmental assistantships and fellowships (tuition + stipend + health insurance). Applicants who ultimately want PhD should apply directly to PhD program. Application fee via Rackham.",
        "url": "details/umich-che-phd.html",
    },
    {
        "id": "ubc-botany-phd",
        "s": "ubc",
        "n": "植物学博士",
        "en": "PhD in Botany (University of British Columbia, Faculty of Science, Department of Botany; research-based thesis; closely linked to Zoology PhD in Faculty of Science)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4-5 years full-time residential; fall primary (September 2027) with January intake also available; **supervisor must be identified and agree to accept before application**; supervisory committee; thesis proposal and oral defense; most students start in September",
        "ddl": "Fall 2027 (September): application opens September 20, 2026. **Canadian and International Applicant Deadline January 10, 2027**. Transcript deadline January 15, 2027; Referee deadline January 20, 2027. January 2028 intake: opens November 1, 2026, deadline July 1, 2027. Strong students encouraged to apply by December 31 for scholarship consideration.",
        "lang": "TOEFL iBT minimum 90 (sectional 22/22/22/22) / IELTS Academic 6.5 (sectional 6.0) / Duolingo DET 125 (sectional 115/120/120/115); ETS UBC code 0965; English-medium undergraduate exempts; scores within 2 years.",
        "test": {"cls": "GRE NOT REQUIRED (UBC Botany Department does not list GRE as required for PhD admission. Subject tests not required. 3 LOR; CV; scanned/unofficial transcripts; minimum B+ average in last 2 years; bachelor's in botany/biology/related science; **supervisor must be contacted and agree before application - students who do not hear back from potential supervisors are rarely admitted**)."},
        "tui": "UBC Botany PhD funded through departmental RA/TA and faculty research grants; minimum stipend package set by Faculty of Graduate and Postdoctoral Studies; international differential tuition waived through assistantships. Application fee ~$150 CAD.",
        "url": "details/ubc-botany-phd.html",
    },
]

DETAIL_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{school} - {en}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;max-width:960px;margin:24px auto;padding:0 20px;color:#222;line-height:1.6}}
h1{{font-size:24px;border-bottom:2px solid #1a73e8;padding-bottom:8px}}
h2{{font-size:18px;color:#1a73e8;margin-top:24px}}
.card{{background:#f8f9fa;border-left:4px solid #1a73e8;padding:12px 16px;margin:12px 0;border-radius:4px}}
.meta{{display:grid;grid-template-columns:120px 1fr;gap:6px 12px;font-size:14px}}
.meta b{{color:#555}}
ul{{margin:6px 0;padding-left:20px}}
.note{{background:#fff3cd;border-left-color:#ffc107;padding:10px 14px;margin-top:16px;font-size:13px}}
a{{color:#1a73e8}}
</style>
</head>
<body>
<h1>{school} - {en}</h1>
<div class="card">
<div class="meta">
<b>Degree</b><span>{deg}</span>
<b>Level</b><span>Research Doctorate (PhD)</span>
<b>STEM</b><span>{stem_label}</span>
<b>Duration</b><span>{dur}</span>
<b>Deadline</b><span>{ddl}</span>
<b>Language</b><span>{lang}</span>
<b>Standardized</b><span>{test_cls}</span>
<b>Funding</b><span>{tui}</span>
</div>
</div>

<h2>Program Overview</h2>
<div class="card">
{overview}
</div>

<h2>Admissions Requirements</h2>
<div class="card">
{requirements}
</div>

<h2>Research Areas</h2>
<div class="card">
{research}
</div>

<h2>Official Source</h2>
<div class="card">
{source}
</div>

<div class="note">
<strong>Note:</strong> Research-oriented PhD in Chemical Engineering / Botany at five top-ranked U.S. and Canadian universities. Admitted PhD students receive full financial support (tuition + stipend + health insurance). Admission statistics shown are distribution ranges, not minimum thresholds. Course/credit details pending department bulletin verification. All five programs are STEM-designated per NSF GRFP / CIP codes. Key trend: MIT ChemE and UMich ChemE do not require or accept GRE; Berkeley CBE explicitly no longer considers GRE; UBC Botany does not require GRE. <strong>Exception: UCSD CENG still requires GRE General Test for PhD applicants (optional for MS) - outlier in the broader engineering PhD trend toward GRE-free.</strong> Canadian model: supervisor must be confirmed before application at UBC Botany.
</div>
</body>
</html>
"""

PAGES = {
    "mit-cheme-phd": {
        "school": "Massachusetts Institute of Technology, Department of Chemical Engineering",
        "en": "PhD in Chemical Engineering (PhD / ScD)",
        "deg": "Doctor of Philosophy (PhD) / Doctor of Science (ScD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5-6 years full-time residential; fall-only; single admission for PhD and MSCEP; research advisor by end of first year; thesis proposal, general exam, defense; January interview for invited PhD candidates",
        "ddl": "Fall 2027 (Sept): opens Sept 15, 2026. **Deadline December 1, 2026 at 23:59 EST**. Fee $90. PhD interview Jan; decisions rolling Jan-Mar; visit weekend March; April 15 CGS reply.",
        "lang": "TOEFL iBT 100 / IELTS 7.0 / Duolingo DET 135 / Cambridge English; ETS MIT 3514; English-medium exempts; scores within 5 years.",
        "test_cls": "GRE NOT REQUIRED/ACCEPTED (MIT ChemE: 'ChemE does not accept GRE scores and will not consider GRE scores in the evaluation of MSCEP and PhD applications.' Exception: PhDCEP (with Sloan) self-reported GRE recommended. 3 LOR; SOP; CV max 2 pages; scanned transcripts; chemistry/bio/physics/math/CS background).",
        "tui": "Full funding for admitted PhD via RA/TA and MIT fellowships (tuition + stipend + health insurance). Fee $90. Fall-only admission.",
        "overview": "The MIT Department of Chemical Engineering offers a single graduate admission process leading to both the Master of Science in Chemical Engineering Practice (MSCEP) and the Doctor of Philosophy (PhD) / Doctor of Science (ScD). The PhDCEP (Chemical Engineering Practice PhD, in partnership with MIT Sloan) is a separate program for mid-career engineers, requiring 6-24 months professional work experience and recommending self-reported GRE. The traditional PhD/ScD program admits full-time students for fall entry only; research advisor assignment is made by the end of the first year, and PhD candidates are invited to interview with the ChemE admissions committee in January. The program evaluates candidates on analytical and scientific preparation (chemistry, biology, physics, mathematics, computer science relevant to the field), character, and communication skills.",
        "requirements": "<ul><li>Bachelor's degree in chemical engineering or related engineering/science</li><li>GRE NOT required/accepted (MIT ChemE does not consider GRE for PhD/ScD/MSCEP; exception: PhDCEP self-reported GRE recommended)</li><li>TOEFL iBT 100 / IELTS 7.0 / DET 135 / Cambridge English (non-native English); ETS 3514; English-medium exempts</li><li>MIT online application (apply.mit.edu)</li><li>Statement of Purpose</li><li>3 letters of recommendation</li><li>Curriculum vitae / resume (max 2 pages, 12pt font, 1 inch margins, including honors/awards/fellowships)</li><li>Scanned copies of college transcripts</li><li>**Deadline December 1, 2026 at 23:59 EST**</li><li>Fall-only admission; on-campus residential</li><li>Application fee $90</li><li>PhD candidates invited to interview in January</li></ul>",
        "research": "<ul><li>Biochemical engineering and biotechnology</li><li>Energy and sustainability (batteries, fuel cells, carbon capture, renewable energy)</li><li>Materials science and engineering (polymers, nanostructured materials, soft matter)</li><li>Thermodynamics and statistical mechanics</li><li>Reaction engineering and catalysis</li><li>Transport phenomena and fluid mechanics</li><li>Process systems engineering and control</li><li>Bioengineering and biomedical engineering</li><li>Environmental engineering and climate science</li><li>Computational molecular science and simulation</li><li>Nuclear engineering (joint with NSE)</li></ul>",
        "source": '<a href="https://cheme.mit.edu/academics/graduate-students/apply/" target="_blank">MIT ChemE Apply (Dec 1, 23:59 EST; GRE not required/accepted; TOEFL/IELTS/Cambridge/DET for international; 3 LOR; CV max 2 pages; fee $90)</a> | <a href="https://oge.mit.edu/programs/chemical-engineering/" target="_blank">MIT OGE Chemical Engineering (Dec 1 at 11:59 PM ET; fee $90; NSF GRFP Engineering; STEM eligible; GRE not accepted for MSCEP/PhD; PhDCEP self-reported GRE recommended; ETS 3514)</a> | <a href="https://cheme.mit.edu/academics/graduate-students/faqs/" target="_blank">MIT ChemE Admission FAQ (same requirements for PhD and MSCEP; PhDCEP requires 6-24 months professional experience; PhD interview January; decisions rolling Jan-Mar; visit weekend March; April 15 reply)</a>',
    },
    "berkeley-cbe-phd": {
        "school": "UC Berkeley, College of Chemistry, Department of Chemical and Biomolecular Engineering",
        "en": "PhD in Chemical and Biomolecular Engineering (CBE)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5-6 years full-time residential; fall-only; 18 units letter-graded (9 minimum from five core courses: math, thermodynamics, reaction engineering, transport phenomena); ChE 375 Pedagogy required; department colloquium; two departmental exams; thesis research from second semester; designated emphasis (DE) options",
        "ddl": "Fall 2027 (August): application opens September 2026. **Deadline December 1, 2026 at 8:59 PM Pacific Time**. Fall admission only; no Spring/Summer. Decisions by early March.",
        "lang": "TOEFL iBT 90 / IELTS Academic 7.0 (Berkeley Graduate Division minimum); ETS Berkeley 4833; English-medium may be exempted; scores within 2 years.",
        "test_cls": "GRE NOT CONSIDERED (Berkeley CBE: 'The faculty of the Department of Chemical and Biomolecular Engineering (CBE) at UC Berkeley have determined the Graduate Records Exam (GRE) is a proven identifier of race and socio-economic status... CBE will no longer consider it for admission.' Subject tests not required. 3 LOR; SOP; Personal History Statement; transcripts; no MS required to apply for doctorate).",
        "tui": "CBE PhD students typically receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance). MS research track currently paused; PDP professional MS is separate.",
        "overview": "The UC Berkeley Department of Chemical and Biomolecular Engineering (CBE) in the College of Chemistry offers a research-intensive PhD in Chemical and Biomolecular Engineering. The PhD requires 18 units of letter-graded coursework in residence, with a minimum of 9 units from the five core chemical engineering courses covering mathematics, thermodynamics, reaction engineering, and transport phenomena. All PhD students are required to take ChE 375 Pedagogy and attend the department colloquium. Two departmental examinations are required during the degree. Students begin thesis research with a faculty advisor starting the second semester. The department does not require a master's degree to apply for the doctorate; most admitted students have completed an undergraduate program in chemical engineering, though admission is possible for students with related backgrounds. The MS research track is currently paused for admissions; the PDP (Professional Master's Program) is a separate professional degree.",
        "requirements": "<ul><li>Bachelor's degree in chemical engineering or related engineering/science</li><li>No master's degree required to apply for doctorate</li><li>GRE NOT considered (Berkeley CBE explicitly no longer considers GRE; subject tests also not required)</li><li>TOEFL iBT 90 / IELTS 7.0 (non-native English); ETS 4833; English-medium may be exempted</li><li>Berkeley Graduate Division online application</li><li>Statement of Purpose</li><li>Personal History Statement (required for all applicants)</li><li>3 letters of recommendation</li><li>Transcripts</li><li>**Deadline December 1, 2026 at 8:59 PM Pacific Time**</li><li>Fall-only admission; on-campus residential</li><li>18 units letter-graded coursework; ChE 375 Pedagogy required</li></ul>",
        "research": "<ul><li>Biochemical engineering and bioengineering</li><li>Energy and climate (renewable energy, carbon capture, batteries, fuel cells)</li><li>Materials science and engineering (polymers, soft matter, nanostructures, 2D materials)</li><li>Thermodynamics and statistical mechanics</li><li>Reaction engineering and catalysis</li><li>Transport phenomena and fluid mechanics</li><li>Process systems engineering, control, and AI</li><li>Environmental engineering and sustainability</li><li>Quantitative and computational biology</li><li>Designated Emphasis (DE) options in areas like Biotechnology, Energy, and New Energy</li></ul>",
        "source": '<a href="https://chemistry.berkeley.edu/grad/cbe/phd/admission" target="_blank">Berkeley CBE PhD Admission (Dec 1, 2026 8:59 PM; GRE no longer considered; 3 LOR; SOP + Personal History Statement; fall-only; 18 units; ChE 375 Pedagogy)</a> | <a href="https://grad.berkeley.edu/program/chemical-and-biomolecular-engineering-phd/" target="_blank">Berkeley Graduate Division: CBE PhD (Dec 1, 2026; Fall only; GRE: No; 201 Gilman Hall; chegrad@cchem.berkeley.edu; designated emphasis options available)</a> | <a href="https://chemistry.berkeley.edu/grad/cbe/phd" target="_blank">Berkeley CBE PhD Program Requirements (18 units letter-graded; 9 units minimum from five core courses; ChE 375 Pedagogy; department colloquium; two departmental exams; research from second semester)</a>',
    },
    "ucsd-ceng-phd": {
        "school": "UC San Diego, Aiiso Yufeng Li Family Department of Chemical and Nano Engineering",
        "en": "PhD in Chemical Engineering (with Multi-scale Biology specialization option)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5 years full-time residential; fall-only (September); 36+ units graduate coursework; Preliminary Qualifying Examination; dissertation research and defense; direct entry from BS to PhD allowed; MS may be earned en route",
        "ddl": "Fall 2027 (September): application opens September 2, 2026. **PhD deadline December 9, 2026**. MS deadline July 14, 2027 (rolling). Fall admission only; no Winter/Spring. Decisions by early March.",
        "lang": "TOEFL iBT 85 / IELTS Academic 7.0 / PTE Academic 65 / Duolingo DET 120 (UCSD minimum); ETS UCSD 4836; English-medium may be exempted; scores within 2 years.",
        "test_cls": "GRE REQUIRED FOR PHD (UCSD CENG: 'For Fall 2027 admissions, submission of GRE scores is optional for MS candidates but mandatory for PhD candidates.' Note: exception to broader engineering PhD trend toward GRE-free. 3 LOR; SOP; CV; transcripts; minimum GPA 3.0/4.0; BS in chemical engineering or related engineering/science/math).",
        "tui": "CENG PhD students typically receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance). Minimum GPA 3.0; typical admitted higher. Fall-only admission.",
        "overview": "The UCSD Aiiso Yufeng Li Family Department of Chemical and Nano Engineering offers MS and PhD degrees in Chemical Engineering and NanoEngineering. The PhD in Chemical Engineering includes an optional specialization in Multi-scale Biology. Admission requires at least a Bachelor of Science in some branch of engineering, sciences, or mathematics, with an overall GPA of 3.0, and three letters of recommendation. Students may apply directly to the PhD program without a master's degree. After completing the MS degree requirements (or equivalent coursework), PhD students work with faculty advisors to prepare for the Preliminary Qualifying Examination and dissertation research. The department only admits for Fall; no Winter or Spring admission. Fall 2027 application opens September 2, 2026.",
        "requirements": "<ul><li>Bachelor's degree in chemical engineering or related engineering/science/math</li><li>Minimum GPA 3.0/4.0 (typical admitted higher)</li><li>**GRE REQUIRED for PhD applicants** (optional for MS; exception to broader engineering PhD trend)</li><li>TOEFL iBT 85 / IELTS 7.0 / PTE 65 / DET 120 (non-native English; UCSD minimum); ETS 4836; English-medium may be exempted</li><li>UCSD Graduate Division online application</li><li>Statement of Purpose</li><li>3 letters of recommendation (online only)</li><li>CV / resume</li><li>Transcripts</li><li>**PhD deadline December 9, 2026**; MS deadline July 14, 2027 (rolling)</li><li>Fall-only admission; on-campus residential</li><li>Direct entry from BS to PhD allowed; MS en route option</li></ul>",
        "research": "<ul><li>Biochemical engineering and biotechnology</li><li>Nanoengineering and nanoscience</li><li>Energy and sustainability (batteries, solar, fuel cells)</li><li>Materials science and engineering (polymers, 2D materials, nanostructures)</li><li>Fluid mechanics and transport phenomena</li><li>Reaction engineering and catalysis</li><li>Process systems engineering and control</li><li>Multi-scale Biology specialization (joint with bioengineering)</li><li>Environmental engineering and climate science</li><li>Computational molecular engineering</li><li>Quantitative and systems biology</li></ul>",
        "source": '<a href="https://www-ne.ucsd.edu/graduate-programs/admissions/faqs" target="_blank">UCSD CENG/NANO Graduate Admissions FAQ (Fall 2027: opens Sep 2, 2026; PhD deadline Dec 9, 2026; MS deadline Jul 14, 2027; GRE required for PhD, optional for MS; GPA 3.0; fall-only)</a> | <a href="https://neweb.ucsd.edu/graduate-programs/admissions" target="_blank">UCSD CENG Graduate Admissions (BS in engineering/science/math; GPA 3.0; 3 LOR; TOEFL iBT 85 / IELTS 7.0 / PTE 65 / DET 120; GRE optional for MS but mandatory for PhD; fall-only)</a> | <a href="https://catalog.ucsd.edu/curric/NANO-gr.html" target="_blank">UCSD Catalog: NanoEngineering Graduate (PhD in Chemical Engineering and PhD in Chemical Engineering with Multi-scale Biology specialization; GRE required for all applicants; TOEFL 85 / IELTS 7.0 / PTE 65 / DET 120; Preliminary Qualifying Examination; dissertation defense)</a>',
    },
    "umich-che-phd": {
        "school": "University of Michigan Ann Arbor, Department of Chemical Engineering (Rackham Graduate School)",
        "en": "PhD in Chemical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "4-5 years full-time residential; fall primary (September); winter (January) limited; direct BS-to-PhD entry; MS-on-way option; thesis research; qualifying exam; dissertation defense; typically 5 years for direct BS entry",
        "ddl": "Fall 2027 (September): **PhD deadline December 1, 2026**. MS deadline January 15, 2027. Winter term: deadline October 1 (rarely admitted). Decisions rolling January-March for PhD; February-March for MS; April 15 CGS reply.",
        "lang": "TOEFL iBT 100 / IELTS Academic 7.0; ETS UMich Rackham code 1839; English-medium exempts; typical admitted PhD: TOEFL 109 (iBT) / IELTS 7.0; scores within 2 years.",
        "test_cls": "GRE NOT REQUIRED (UMich ChemE: 'GRE scores are no longer required.' Contacting individual faculty does not influence admissions decision. 3 LOR (prefer professors and research advisors); SOP; transcripts; typical admitted PhD GPA 3.6/4.0; BS in chemical engineering or related).",
        "tui": "PhD students typically receive full funding through Rackham/departmental assistantships and fellowships (tuition + stipend + health insurance). Applicants who ultimately want PhD should apply directly to PhD program. Application fee via Rackham.",
        "overview": "The University of Michigan Department of Chemical Engineering offers PhD and MSE degrees through the Rackham Graduate School. The PhD program admits students directly from a bachelor's degree (no MS required); students earn an MS on the way to the PhD if desired. Admissions are reviewed by the departmental graduate admissions committee, not by individual faculty. Fall is the primary entry; winter (January) admission is rare. The PhD application deadline is December 1; the MSE deadline is January 15. Decisions for PhD are mailed between January and March, with offers due April 15. Typical admitted PhD students have a GPA of 3.6/4.0 and TOEFL iBT around 109 (non-native English).",
        "requirements": "<ul><li>Bachelor's degree in chemical engineering or related engineering/science</li><li>No master's required to apply for PhD; direct BS-to-PhD entry allowed</li><li>GRE NOT required (UMich ChemE explicitly states GRE scores are no longer required)</li><li>TOEFL iBT 100 / IELTS 7.0 (non-native English); ETS 1839; English-medium exempts; typical admitted TOEFL 109</li><li>Rackham Graduate School online application</li><li>Statement of Purpose</li><li>3 letters of recommendation (prefer professors and research advisors; electronic via online application)</li><li>Transcripts (scanned/unofficial for application)</li><li>Typical admitted PhD GPA 3.6/4.0</li><li>**PhD deadline December 1, 2026**; MSE deadline January 15, 2027</li><li>Fall primary; winter (October 1 deadline) rarely admitted</li><li>Contacting individual faculty does not influence admissions decision</li></ul>",
        "research": "<ul><li>Biochemical engineering and biotechnology</li><li>Energy and sustainability (batteries, fuel cells, carbon capture, renewable energy)</li><li>Materials science and engineering (polymers, nanostructures, soft matter)</li><li>Thermodynamics and statistical mechanics</li><li>Reaction engineering and catalysis</li><li>Transport phenomena and fluid mechanics</li><li>Process systems engineering, control, and AI</li><li>Environmental engineering and climate science</li><li>Computational molecular science and simulation</li><li>Quantitative biology and biomedical engineering</li></ul>",
        "source": '<a href="https://che.engin.umich.edu/graduate/prospective-students/" target="_blank">UMich ChemE Prospective Students (PhD Dec 1, MSE Jan 15; winter Oct 1; GRE no longer required; 3 LOR; contact faculty does not influence decision; apply directly to PhD)</a> | <a href="https://che.engin.umich.edu/graduate/prospective-students/admissions-timeline/" target="_blank">UMich ChemE Admissions Timeline (PhD Dec 1; MSE Jan 15; decisions rolling Jan-Mar; offers due April 15; winter admission rare)</a> | <a href="https://che.engin.umich.edu/graduate/prospective-students/toefl-gre/" target="_blank">UMich ChemE TOEFL and GRE (GRE no longer required; TOEFL iBT 100 / IELTS 7.0; typical admitted PhD: GPA 3.6, TOEFL 109 / IELTS 7.0; ETS code 1839)</a>',
    },
    "ubc-botany-phd": {
        "school": "University of British Columbia, Department of Botany (Faculty of Science)",
        "en": "PhD in Botany",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Life Sciences / CIP 26.xx)",
        "dur": "4-5 years full-time residential; fall primary (September) with January intake also available; **supervisor must be identified and agree before application**; supervisory committee; thesis proposal and oral defense; most students start in September",
        "ddl": "Fall 2027 (September): opens September 20, 2026. **Canadian and International deadline January 10, 2027**. Transcript deadline January 15; Referee deadline January 20. January 2028 intake: opens November 1, 2026, deadline July 1, 2027. Strong students encouraged to apply by December 31 for scholarship consideration.",
        "lang": "TOEFL iBT 90 (sectional 22/22/22/22) / IELTS 6.5 (sectional 6.0) / Duolingo DET 125 (sectional 115/120/120/115); ETS UBC 0965; English-medium exempts; scores within 2 years.",
        "test_cls": "GRE NOT REQUIRED (UBC Botany does not list GRE as required for PhD admission. Subject tests not required. 3 LOR; CV; scanned transcripts; minimum B+ average last 2 years; bachelor's in botany/biology/related science; **supervisor must be contacted and agree before application - students who do not hear back from potential supervisors are rarely admitted**).",
        "tui": "UBC Botany PhD funded through departmental RA/TA and faculty research grants; minimum stipend package set by Faculty of Graduate + Postdoctoral Studies; international differential tuition waived through assistantships. Application fee ~$150 CAD.",
        "overview": "The UBC Department of Botany offers a research-based PhD in Botany on the Vancouver campus. The program requires a research supervisor who is a UBC faculty member; admission is contingent on that supervisor agreeing to accept the student and provide funding. Applicants are strongly advised to contact potential supervisors by email before submitting the online application; students who do not make contact with potential supervisors are rarely admitted. The PhD has a five-stage admission process: (1) meet minimum academic requirements; (2) find and contact potential supervisor(s); (3) complete the UBC online application; (4) review by the Botany Graduate Admissions Committee; (5) acceptance by a supervisor. Most students start in September, but January admission is also possible. Strong students should apply by December 31 to be considered for scholarships.",
        "requirements": "<ul><li>Bachelor's degree or MSc in botany, biology, or related science</li><li>Minimum B+ average in last 2 years of study</li><li>GRE NOT required (Botany does not list GRE as required)</li><li>TOEFL iBT 90 / IELTS 6.5 / Duolingo DET 125 (non-native English); ETS 0965; English-medium exempts</li><li>UBC Graduate and Postdoctoral Studies online application</li><li>CV</li><li>3 letters of recommendation</li><li>Scanned/unofficial transcripts</li><li>**Supervisor must be contacted and agree to accept before application (students who do not hear back from potential supervisors are rarely admitted)**</li><li>**Fall 2027 deadline January 10, 2027**; transcript deadline January 15; referee deadline January 20</li><li>January 2028 intake: deadline July 1, 2027</li><li>Strong students encouraged to apply by December 31 for scholarship consideration</li></ul>",
        "research": "<ul><li>Plant ecology and evolutionary biology</li><li>Plant systematics and biodiversity</li><li>Plant physiology and biochemistry</li><li>Mycology and fungal biology</li><li>Phycology (algae)</li><li>Phytopathology and plant-microbe interactions</li><li>Conservation biology and biodiversity</li><li>Molecular and cell biology of plants</li><li>Interdisciplinary with Zoology PhD (separate department) and Biodiversity Research Centre</li><li>Field stations and research forests at UBC</li></ul>",
        "source": '<a href="https://www.grad.ubc.ca/prospective-students/graduate-degree-programs/phd-botany" target="_blank">UBC PhD in Botany (Fall 2027: opens Sep 20, 2026; Canadian and International deadline Jan 10, 2027; transcript deadline Jan 15; referee deadline Jan 20; January 2028 intake opens Nov 1, 2026, deadline Jul 1, 2027)</a> | <a href="https://botany.ubc.ca/graduates/prospective-students/" target="_blank">UBC Botany Prospective Students (5-stage admission: meet requirements, find/contact supervisor, complete application, committee review, supervisor acceptance; students who do not hear back from potential supervisors are rarely admitted; apply by Dec 31 for scholarships)</a> | <a href="https://botany.ubc.ca/graduates/how-to-apply" target="_blank">UBC Botany How to Apply (Fall: online application by January 10; January entry: by July 1; late applications may be considered; contact supervisor before applying)</a>',
    },
}

# Write detail pages
for p in PROGRAMS:
    key = p["id"]
    d = PAGES[key]
    html = DETAIL_TEMPLATE.format(
        school=d["school"], en=d["en"], deg=d["deg"], stem_label=d["stem_label"],
        dur=d["dur"], ddl=d["ddl"], lang=d["lang"], test_cls=d["test_cls"], tui=d["tui"],
        overview=d["overview"], requirements=d["requirements"],
        research=d["research"], source=d["source"],
    )
    path = os.path.join(DET, key + ".html")
    with open(path, "w", encoding="utf-8") as f:
        f.write(html)
    print(f"Wrote: {key}.html")

# Append PROGRAMS
idx_path = os.path.join(BASE, "index_main.html")
with open(idx_path, "r", encoding="utf-8") as f:
    html = f.read()

def build_entry(p):
    return ('{{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(
        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"]["cls"].replace('"', "'"),
        tui=p["tui"].replace('"', "'"), url=p["url"],
    )

new_entries = ",\n".join(build_entry(p) for p in PROGRAMS)

m = re.search(r'const\s+PROGRAMS\s*=\s*\[', html)
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
insert_pos = i - 1
prefix = html[:insert_pos].rstrip()
suffix = html[insert_pos:]
if prefix.endswith('{'):
    new_block = prefix + "\n" + new_entries + "\n" + suffix
else:
    new_block = prefix + ",\n" + new_entries + "\n" + suffix

# Append VD on new_block (re-locate to avoid offset)
vd_entries = ",\n".join(f'"{p["url"]}"' for p in PROGRAMS)
m2 = re.search(r'VERIFIED_DETAILS\s*=\s*new\s+Set\s*\(\s*\[', new_block)
vstart = m2.end()
vdepth = 1
j = vstart
while j < len(new_block) and vdepth > 0:
    c = new_block[j]
    if c == '[': vdepth += 1
    elif c == ']': vdepth -= 1
    j += 1
vinsert_pos = j - 1
vprefix = new_block[:vinsert_pos].rstrip()
vsuffix = new_block[vinsert_pos:]
if vprefix.endswith(','):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
elif vprefix.endswith('['):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
else:
    new_block = vprefix + ",\n" + vd_entries + "\n" + vsuffix

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

print(f"Appended {len(PROGRAMS)} PROGRAMS entries and {len(PROGRAMS)} VD entries")
print(f"Done. File size: {os.path.getsize(idx_path)}")
