# -*- coding: utf-8 -*-
"""Round 241: batch add 5 Chemical Engineering PhD (continued)
- Princeton CBE PhD (Dec 1, GRE not required/accepted; fee $75; 10 courses incl ethics)
- Caltech ChemE PhD (Dec 1, GRE recommended not required; on-site interviews Feb 25-27, 2027)
- Stanford ChemE PhD (Dec 1 PST, GRE no longer required/accepted; 135 units; 3.0 GPA)
- Cornell CBE PhD (Dec 15, GRE not required; video essay required; 138 credits; full funding)
- Georgia Tech ChBE PhD (Jan 4, GRE per department policy; TOEFL 90/IELTS 7.0; 5 core courses)
"""
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": "princeton-cbe-phd",
        "s": "princeton",
        "n": "化学与生物分子工程博士",
        "en": "PhD in Chemical and Biological Engineering (Princeton University, School of Engineering and Applied Science, Department of Chemical and Biological Engineering, CBE; doctoral-centered program; MSE and M.Eng. are separate master's tracks)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5 years full-time residential; fall-only; minimum 10 graduate-level courses (5 CBE-specific + 4 electives + 1 engineering ethics); adviser selection by mid-December; CBE 507 faculty research presentations; thesis proposal, general exam, defense",
        "ddl": "Fall 2027 (September): application opens early September 2026. **Deadline December 1, 2026 at 11:59 PM Eastern Standard Time**. Application fee $75. Fee waivers available to domestic students in financial need (contact SEAS Associate Dean of Diversity). Decisions by mid-March; April 15 CGS reply.",
        "lang": "TOEFL iBT / IELTS Academic required for international students who completed undergraduate degree in a country where native language is not English; ETS Princeton code 2613; exceptions per Graduate School policy; scores valid 2 years.",
        "test": {"cls": "GRE NOT REQUIRED/ACCEPTED (Princeton CBE: 'No GRE tests are required, nor are GRE scores accepted as part of the application.' Subject tests also not required. 3 LOR; Statement of Academic Purpose; CV/Resume; Transcripts; Fall semester grades; optional diversity statement <=250 words; no minimum GPA cutoff)."},
        "tui": "Princeton CBE PhD students receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance). Application fee $75. MSE and M.Eng. are typically self-supported (employer or external fellowship). Fall-only admission.",
        "url": "details/princeton-cbe-phd.html",
    },
    {
        "id": "caltech-cbe-phd",
        "s": "caltech",
        "n": "化学工程博士",
        "en": "PhD in Chemical Engineering (California Institute of Technology, Division of Chemistry and Chemical Engineering, CCE; doctoral-only - master's degree in chemical engineering is not ordinarily offered except under special circumstances with prior approval)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years full-time residential; fall-only; on-site interview weekend February 25-27, 2027 at Caltech; thesis research with faculty adviser; candidacy exam; dissertation defense; financial support for tuition and living expenses throughout",
        "ddl": "Fall 2027 (September): application opens September 2026. **Deadline December 1, 2026**. Interview invites sent by December 23, 2026. In-person interviews at Caltech February 25-27, 2027. Admission decisions released by March 8, 2027. All decisions posted no later than April 1.",
        "lang": "TOEFL iBT / IELTS Academic required for international students whose native language is not English; ETS Caltech code 4034; Caltech accepts self-reported scores and validates electronically with ETS; no minimum score requirement per Graduate Office.",
        "test": {"cls": "GRE RECOMMENDED (Caltech CCE: 'GRE scores are not required. Absence of GRE scores will not be negatively considered for otherwise qualified applicants. If an applicant believes that GRE scores strengthen the application and chooses to submit them, submitted GRE scores will be considered.' Per Caltech Required Tests PDF: Chemical Engineering PhD = R (Recommended). 3 LOR; SOP; CV; transcripts; research experience including publications)."},
        "tui": "All admitted Caltech PhD students receive financial support covering tuition and living expenses (through research/teaching assistantships and fellowships). Most funding sources require work authorization in the United States. Master's in chemical engineering is not ordinarily offered. Application via CollegeNET applyweb.com/caltgapp.",
        "url": "details/caltech-cbe-phd.html",
    },
    {
        "id": "stanford-cheme-phd",
        "s": "stanford",
        "n": "化学工程博士",
        "en": "PhD in Chemical Engineering (Stanford University, School of Engineering, Department of Chemical Engineering; doctoral research degree; MS via HCP Honors Cooperative Program is separate online/part-time track and excluded from this catalog)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years full-time residential; Autumn quarter entry only; minimum 135 graduate units (including minimum 39 units of coursework: 15 units CHEMENG core + 6 units CHEMENG 4xx); minimum 3.0 GPA maintained; candidacy exam; dissertation adviser; dissertation defense; MS not required as prerequisite",
        "ddl": "Autumn 2027 (September): application opens mid-September 2026. **Deadline December 1, 2026 at 11:59 PM Pacific Time**. No late applications. Knight-Hennessy Scholars separate deadline October 6, 2026 at 1:00 PM Pacific (independent application). Decisions rolling January-March; April 15 CGS reply.",
        "lang": "TOEFL iBT required for international students whose native language is not English; ETS Stanford code 4701; IELTS Academic accepted; scores valid 2 years; English-medium undergraduate exempts per Graduate Admissions policy.",
        "test": {"cls": "GRE NO LONGER REQUIRED/ACCEPTED (Stanford ChemE: 'GRE scores are no longer required or accepted as part of an applicant's application materials.' No minimum GPA, no particular undergraduate major required. 3 LOR; SOP; research experience summary for PhD; application fee; TOEFL scores; Stanford does not accept LOR via Interfolio)."},
        "tui": "Stanford ChemE PhD students typically receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance). Knight-Hennessy Scholarship available for independent application. Autumn-only admission; on-campus residential. MS via HCP is part-time online and excluded from this catalog.",
        "url": "details/stanford-cheme-phd.html",
    },
    {
        "id": "cornell-cbe-phd",
        "s": "cornell",
        "n": "化学工程博士",
        "en": "PhD in Chemical Engineering (Cornell University, College of Engineering, Robert F. Smith School of Chemical and Biomolecular Engineering; Ithaca NY; field includes biochemical engineering concentration; MS and MEng are separate master's tracks)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5 years minimum full-time residential; fall-only admission (no spring); minimum 138 credits; minimum 5 semesters; core courses CHEME 6920, 6130, 6240; Responsible Conduct of Research training required; ORCID required; Student Progress Reviews start Year 1; A Exam (candidacy) Summer of Year 3; dissertation defense",
        "ddl": "Fall 2027 (August): application opens September 2026. **Deadline December 15, 2026**. No spring admission. Completed applications received by January 7 are automatically considered for financial aid. Decisions typically by late February/early March; no later than mid-May. April 15 CGS reply.",
        "lang": "TOEFL iBT / IELTS Academic required for international students whose native language is not English; ETS Cornell Graduate School code 2198; English proficiency per Graduate School requirements; scores valid 2 years.",
        "test": {"cls": "GRE NOT REQUIRED (Cornell CBE: 'GRE scores are not required.' Most applicants have completed accredited chemical engineering curriculum; outstanding chemistry/materials/microbiology/physics undergraduates also encouraged. 3 LOR; video essay required; CV/resume; transcripts; SOP)."},
        "tui": "All admitted Cornell CBE PhD students receive full financial aid: full tuition waiver + 9-month stipend + health insurance (through fellowship, research assistantship, or teaching assistantship). Additional summer support usually available. MS program is self-funded. Fall-only admission; on-campus residential.",
        "url": "details/cornell-cbe-phd.html",
    },
    {
        "id": "gatech-chbe-phd",
        "s": "gatech",
        "n": "化学与生物分子工程博士",
        "en": "PhD in Chemical Engineering (Georgia Institute of Technology, College of Engineering, School of Chemical and Biomolecular Engineering, ChBE; also participates in PhD in Bioengineering as home school; MS track has earlier deadline)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "~5 years full-time residential; fall primary admission; 5 core 3-credit-hour courses with minimum cumulative GPA 3.0 and minimum GPA 3.2 in the 5 core courses; qualifying exam in second semester; predoctoral review at least 6 months before thesis defense; thesis defense by Doctoral Examination Committee",
        "ddl": "Fall 2027 (August): application opens September 2026. **PhD deadline January 4, 2027**. MS deadline January 15, 2027. Fall admission only. Decisions rolling February-March; April 15 CGS reply.",
        "lang": "TOEFL iBT minimum 90 (minimum section scores 19 each) / IELTS Academic overall 7.0 (minimum band 6.5 R/L/S, 5.5 W); ETS Georgia Tech code 5248; scores valid 2 years; GTLI Upper Advanced 700 Level accepted as alternative.",
        "test": {"cls": "GRE PER DEPARTMENT POLICY (Georgia Tech Graduate Education degree-program page lists TOEFL/IELTS as standardized tests; per broader Georgia Tech engineering PhD trend, GRE is not required; applicants should verify on current ChBE admissions page. 3 LOR; essay questions; resume; Statement of Purpose; BS in engineering or science with 2 years calculus/ODE, 1 year calculus physics, 1 year chemistry preferred)."},
        "tui": "All Georgia Tech ChBE PhD students receive financial assistance through departmental RA/TA and fellowships (tuition + stipend + health insurance). Typical program ~5 years. Fall-only admission; on-campus residential. ChBE also home school for Bioengineering PhD (joint with BME).",
        "url": "details/gatech-chbe-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 / Chemical and Biomolecular Engineering at five additional top-ranked U.S. universities (Princeton, Caltech, Stanford, Cornell, Georgia Tech). 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 CIP code 14.0701. Key trend: Princeton CBE and Stanford ChemE explicitly do not require or accept GRE; Cornell CBE does not require GRE; Caltech ChemE treats GRE as Recommended (absence not penalized); Georgia Tech ChBE standardized tests per current department page. Caltech features on-site interview weekend February 25-27, 2027.
</div>
</body>
</html>
"""

PAGES = {
    "princeton-cbe-phd": {
        "school": "Princeton University, Department of Chemical and Biological Engineering",
        "en": "PhD in Chemical and Biological Engineering (CBE)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5 years full-time residential; fall-only; minimum 10 graduate-level courses (5 CBE-specific + 4 electives + 1 engineering ethics); adviser selection by mid-December; CBE 507 faculty research presentations; thesis proposal, general exam, defense",
        "ddl": "Fall 2027 (September): opens early September 2026. **Deadline December 1, 2026 at 11:59 PM Eastern Standard Time**. Fee $75. Decisions by mid-March; April 15 CGS reply.",
        "lang": "TOEFL iBT / IELTS Academic for international students who completed undergraduate in a non-native-English country; ETS Princeton 2613; exceptions per Graduate School; scores valid 2 years.",
        "test_cls": "GRE NOT REQUIRED/ACCEPTED (Princeton CBE: 'No GRE tests are required, nor are GRE scores accepted as part of the application.' 3 LOR; Statement of Academic Purpose; CV/Resume; Transcripts; Fall semester grades; optional diversity statement <=250 words; no minimum GPA cutoff).",
        "tui": "CBE PhD students receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance). Fee $75. MSE and M.Eng. typically self-supported. Fall-only admission.",
        "overview": "The Princeton Department of Chemical and Biological Engineering (CBE) is centered on the Doctor of Philosophy (PhD) degree; the majority of its graduate students are doctoral candidates. The department also offers M.S.E. and M.Eng. master's degrees geared toward practicing engineers who typically come with financial support from employers or external fellowships. The PhD requires a minimum of 10 graduate-level courses: five specific CBE graduate courses, four electives, and one engineering ethics course. Adviser selection runs from September to December: students receive a packet of available projects, attend CBE 507 faculty research presentations, meet with a minimum of five faculty members, and submit three project choices in mid-December, joining a research group by January. The Graduate School accepts applications once a year for fall entry; no late applications are accepted. Princeton will not offer admission to an applicant seeking a second PhD in the same or similar field.",
        "requirements": "<ul><li>Bachelor's degree (or foreign equivalent) in engineering, science, or related field</li><li>GRE NOT required/accepted (Princeton CBE explicitly does not accept GRE scores; subject tests also not required)</li><li>TOEFL iBT / IELTS Academic for international students who completed undergraduate in a non-native-English country; ETS 2613</li><li>Princeton Graduate School online application</li><li>Statement of Academic Purpose</li><li>3 letters of recommendation</li><li>CV / resume</li><li>Transcripts (in English) from each degree-granting institution</li><li>Fall semester grades (for current seniors)</li><li>Optional diversity statement no more than 250 words</li><li>**Deadline December 1, 2026 at 11:59 PM EST**</li><li>Fall-only admission; on-campus residential</li><li>Application fee $75; fee waivers available to domestic students in financial need (contact SEAS Associate Dean of Diversity and Inclusion)</li><li>Not eligible if applicant already holds a PhD in the same or similar field</li></ul>",
        "research": "<ul><li>Applied and computational mathematics</li><li>Bioengineering and synthetic biology</li><li>Environmental and energy science and technology</li><li>Materials synthesis and processing</li><li>Process engineering and process science</li><li>Thermodynamics and statistical mechanics</li><li>Transport phenomena and fluid mechanics</li><li>Biochemical engineering and biophysics</li><li>Quantitative and systems biology</li><li>Computational molecular science</li><li>Catalysis and reaction engineering</li><li>Soft matter and polymers</li></ul>",
        "source": '<a href="https://cbe.princeton.edu/graduate/how-to-apply" target="_blank">Princeton CBE How to Apply (Dec 1, 11:59 PM EST; GRE not required nor accepted; TOEFL/IELTS for international; 3 LOR; SOP; CV; fee $75; fee waivers for domestic students in need)</a> | <a href="https://gradschool.princeton.edu/academics/degrees-requirements/fields-study/chemical-and-biological-engineering" target="_blank">Princeton Graduate School: CBE Field of Study (PhD 5 years; M.S.E. 1.5-2 years; M.Eng. 1 year; GRE General Test not accepted; fee $75; additional 250-word diversity statement required)</a> | <a href="https://cbe.princeton.edu/graduate/program-details" target="_blank">Princeton CBE Program Details (minimum 10 courses: 5 CBE + 4 electives + 1 engineering ethics; adviser selection Sep/Dec; CBE 507; meet at least 5 faculty; join research group by January)</a>',
    },
    "caltech-cbe-phd": {
        "school": "California Institute of Technology, Division of Chemistry and Chemical Engineering",
        "en": "PhD in Chemical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5-6 years full-time residential; fall-only; on-site interview weekend February 25-27, 2027 at Caltech; thesis research with faculty adviser; candidacy exam; dissertation defense; financial support for tuition and living expenses throughout",
        "ddl": "Fall 2027 (September): application opens September 2026. **Deadline December 1, 2026**. Interview invites sent by December 23, 2026. In-person interviews at Caltech February 25-27, 2027. Admission decisions released by March 8, 2027. All decisions posted no later than April 1.",
        "lang": "TOEFL iBT / IELTS Academic required for international students whose native language is not English; ETS Caltech 4034; Caltech accepts self-reported scores and validates electronically with ETS; no minimum score per Graduate Office.",
        "test_cls": "GRE RECOMMENDED (Caltech CCE: 'GRE scores are not required. Absence of GRE scores will not be negatively considered for otherwise qualified applicants. If an applicant believes that GRE scores strengthen the application and chooses to submit them, submitted GRE scores will be considered.' Per Caltech Required Tests PDF: Chemical Engineering PhD = R (Recommended). 3 LOR; SOP; CV; transcripts; research experience including publications).",
        "tui": "All admitted Caltech PhD students receive financial support covering tuition and living expenses (through research/teaching assistantships and fellowships). Most funding sources require work authorization in the United States. Master's in chemical engineering is not ordinarily offered. Application via CollegeNET applyweb.com/caltgapp.",
        "overview": "The Caltech Division of Chemistry and Chemical Engineering (CCE) offers a doctoral PhD in Chemical Engineering. A master's degree in chemistry or chemical engineering is not ordinarily offered except under special circumstances with prior approval of the Graduate Study Committee. The Chemical Engineering PhD program uses an on-site interview process: applicants are invited to Caltech for in-person research conversations with faculty, supplementing application materials. The typical timeline is: application by December 1, interview invites by December 23, in-person interviews at Caltech February 25-27, 2027, and admission decisions by March 8, 2027. All admitted PhD students are funded for tuition and living expenses throughout the program; most funding sources require U.S. work authorization.",
        "requirements": "<ul><li>Bachelor's degree in science or engineering (related to chemical engineering option)</li><li>GRE RECOMMENDED but not required (Caltech CCE: absence of GRE will not be negatively considered; if submitted, will be considered; per Caltech Required Tests PDF, Chemical Engineering PhD = R Recommended)</li><li>TOEFL iBT / IELTS Academic for international students whose native language is not English; ETS 4034; self-reported accepted and validated electronically</li><li>Caltech Graduate Office online application (via CollegeNET applyweb.com/caltgapp)</li><li>Statement of Purpose</li><li>3 letters of recommendation</li><li>CV / resume</li><li>Transcripts (official required upon enrollment; electronic/unofficial for application)</li><li>Research experience including resulting publications or presentations is valued</li><li>**Deadline December 1, 2026**</li><li>Fall-only admission; on-campus residential</li><li>On-site interview weekend February 25-27, 2027 at Caltech (invitees only)</li><li>Admission decisions by March 8, 2027; all decisions posted by April 1</li><li>Master's in chemical engineering not ordinarily offered (special circumstances only)</li></ul>",
        "research": "<ul><li>Biochemical engineering and molecular biophysics</li><li>Energy and sustainability (combustion, batteries, solar)</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>Computational molecular science and simulation</li><li>Environmental engineering and climate science</li><li>Quantitative and systems biology</li><li>Interdisciplinary with Chemistry, Applied Physics, and Bioengineering options at Caltech</li></ul>",
        "source": '<a href="https://cce.caltech.edu/graduate/graduate-admissions" target="_blank">Caltech CCE Graduate Admissions (deadline Dec 1; GRE not required, absence not penalized, submitted scores considered; master\'s not ordinarily offered; late applications at disadvantage for funding)</a> | <a href="https://cce.caltech.edu/graduate/graduate-chemical-engineering/graduate-admissions-chemical-engineering" target="_blank">Caltech ChemE Graduate Admissions (Dec 1, 2026 deadline; interview invites by Dec 23; in-person interviews Feb 25-27, 2027; decisions by Mar 8, 2027; on-site interview process features deep faculty research conversations)</a> | <a href="https://gradoffice.caltech.edu/documents/32515/AppInstructions_Required_Tests.pdf" target="_blank">Caltech Required Tests PDF (Chemical Engineering PhD = R Recommended; self-reported scores accepted and validated with ETS; no minimum score; institution code 4034)</a>',
    },
    "stanford-cheme-phd": {
        "school": "Stanford University, Department of Chemical Engineering",
        "en": "PhD in Chemical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5-6 years full-time residential; Autumn quarter entry only; minimum 135 graduate units (including minimum 39 units of coursework: 15 units CHEMENG core + 6 units CHEMENG 4xx); minimum 3.0 GPA maintained; candidacy exam; dissertation adviser; dissertation defense; MS not required as prerequisite",
        "ddl": "Autumn 2027 (September): opens mid-September 2026. **Deadline December 1, 2026 at 11:59 PM Pacific Time**. No late applications. Knight-Hennessy Scholars separate deadline October 6, 2026 at 1:00 PM Pacific (independent application). Decisions rolling January-March; April 15 CGS reply.",
        "lang": "TOEFL iBT required for international students whose native language is not English; ETS Stanford 4701; IELTS Academic accepted; scores valid 2 years; English-medium undergraduate exempts per Graduate Admissions policy.",
        "test_cls": "GRE NO LONGER REQUIRED/ACCEPTED (Stanford ChemE: 'GRE scores are no longer required or accepted as part of an applicant's application materials.' No minimum GPA, no particular undergraduate major required. 3 LOR; SOP; research experience summary for PhD; application fee; TOEFL scores; Stanford does not accept LOR via Interfolio).",
        "tui": "Stanford ChemE PhD students typically receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance). Knight-Hennessy Scholarship available for independent application. Autumn-only admission; on-campus residential. MS via HCP is part-time online and excluded from this catalog.",
        "overview": "The Stanford Department of Chemical Engineering offers a research-intensive PhD in Chemical Engineering. The Doctor of Philosophy is awarded after completion of a minimum of 135 graduate units of work, including at least 39 units of coursework (15 units CHEMENG core + 6 units CHEMENG 4xx advanced). Completion of an MS degree is not a prerequisite. A minimum GPA of 3.0 must be maintained throughout the program. To advance to candidacy, students must secure a research dissertation adviser, maintain 3.0+ GPA, pass the candidacy examination, and submit the Candidacy for Doctoral Degree form. The MS program at Stanford ChemE is delivered via the Honors Cooperative Program (HCP) as a part-time/online degree for working professionals; this catalog excludes HCP and only includes the residential PhD. The department accepts applications once per year for Autumn quarter entry; no late applications are accepted.",
        "requirements": "<ul><li>Bachelor's degree from a regionally accredited U.S. institution (or equivalent from a recognized international institution)</li><li>No master's degree required to apply for PhD; no particular undergraduate major required</li><li>GRE no longer required or accepted (Stanford ChemE explicitly no longer considers GRE scores)</li><li>No minimum GPA required for application (minimum 3.0 to maintain in program)</li><li>TOEFL iBT / IELTS Academic for international students whose native language is not English; ETS 4701; scores valid 2 years</li><li>Stanford Graduate Admissions online application</li><li>Statement of Purpose (with summary of research experience for PhD applicants)</li><li>3 letters of recommendation (Stanford does not accept LOR via Interfolio)</li><li>Application fee</li><li>**Deadline December 1, 2026 at 11:59 PM Pacific Time** (Autumn 2027 entry)</li><li>Autumn-only admission; on-campus residential</li><li>Knight-Hennessy Scholars separate deadline October 6, 2026 at 1:00 PM Pacific (independent application)</li><li>All application components including LOR must arrive by deadline</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, 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 climate science</li><li>Computational molecular science and simulation</li><li>Quantitative and systems biology</li><li>Interdisciplinary with Stanford Bio-X, Precourt Institute, and Woods Institute</li></ul>",
        "source": '<a href="https://cheme.stanford.edu/academics-admissions/graduate-admissions/phd-admissions" target="_blank">Stanford ChemE PhD Admissions (Autumn 2027 deadline Dec 1, 2026 11:59 PM PST; GRE no longer required or accepted; 3 LOR; SOP; research experience summary; TOEFL; no late applications; Knight-Hennessy separate Oct 6 deadline)</a> | <a href="https://cheme.stanford.edu/academics-admissions/graduate-admissions" target="_blank">Stanford ChemE Graduate Admissions (no GRE required/accepted; no minimum GPA; no particular undergraduate major; LOR not accepted via Interfolio; MS is HCP online/part-time and excluded)</a> | <a href="https://22-23.bulletin.stanford.edu/programs/CHEME-PHD" target="_blank">Stanford Bulletin: CHEME-PHD (135 graduate units minimum; 39 units coursework including 15 CHEMENG core + 6 CHEMENG 4xx; 3.0 GPA; candidacy exam; dissertation adviser; MS not prerequisite)</a>',
    },
    "cornell-cbe-phd": {
        "school": "Cornell University, Robert F. Smith School of Chemical and Biomolecular Engineering",
        "en": "PhD in Chemical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "5 years minimum full-time residential; fall-only admission (no spring); minimum 138 credits; minimum 5 semesters; core courses CHEME 6920, 6130, 6240; Responsible Conduct of Research training required; ORCID required; Student Progress Reviews start Year 1; A Exam (candidacy) Summer of Year 3; dissertation defense",
        "ddl": "Fall 2027 (August): application opens September 2026. **Deadline December 15, 2026**. No spring admission. Completed applications received by January 7 are automatically considered for financial aid. Decisions typically by late February/early March; no later than mid-May. April 15 CGS reply.",
        "lang": "TOEFL iBT / IELTS Academic required for international students whose native language is not English; ETS Cornell Graduate School 2198; English proficiency per Graduate School requirements; scores valid 2 years.",
        "test_cls": "GRE NOT REQUIRED (Cornell CBE: 'GRE scores are not required.' Most applicants have completed accredited chemical engineering curriculum; outstanding chemistry/materials/microbiology/physics undergraduates also encouraged. 3 LOR; video essay required; CV/resume; transcripts; SOP).",
        "tui": "All admitted Cornell CBE PhD students receive full financial aid: full tuition waiver + 9-month stipend + health insurance (through fellowship, research assistantship, or teaching assistantship). Additional summer support usually available. MS program is self-funded. Fall-only admission; on-campus residential.",
        "overview": "The Cornell Robert F. Smith School of Chemical and Biomolecular Engineering (CBE) in Ithaca, NY offers a PhD in Chemical Engineering with a biochemical engineering concentration. The PhD requires minimum 138 credits and minimum 5 semesters. Required Year 1 courses include CHEME 6920 (Principles and Practices of Graduate Research), CHEME 6130 (Advanced Chemical Engineering Thermodynamics), and CHEME 6240 (Advanced Fluid Mechanics and Heat Transfer). Responsible Conduct of Research training and ORCID are required milestones. Student Progress Reviews begin in Year 1; the A Exam (candidacy examination) is scheduled for the Summer of Year 3. All admitted PhD students receive full financial aid: full tuition waiver, 9-month stipend, and health insurance, with additional summer support usually available. Applications received by January 7 are automatically considered for financial aid. The MS program is self-funded; M.Eng. is a separate one-year non-thesis professional degree.",
        "requirements": "<ul><li>Bachelor's degree in chemical engineering or related field (chemistry, materials science, microbiology, physics also encouraged)</li><li>GRE NOT required (Cornell CBE explicitly does not require GRE scores)</li><li>TOEFL iBT / IELTS Academic for international students whose native language is not English; ETS 2198; per Graduate School English proficiency requirements</li><li>Cornell University Graduate School online application</li><li>Field of study: 'Chemical Engineering, Ph.D.'</li><li>Statement of Purpose</li><li>3 letters of recommendation</li><li>CV / resume</li><li>Video essay required (per CBE admissions)</li><li>Transcripts</li><li>**Deadline December 15, 2026** (Fall entry only; no spring admission)</li><li>Applications received by January 7 automatically considered for financial aid</li><li>Fall-only admission; on-campus residential (Ithaca, NY)</li><li>Minimum 138 credits; minimum 5 semesters</li><li>Core courses CHEME 6920, 6130, 6240; CPR certification before A Exam</li><li>A Exam (candidacy) Summer of Year 3</li></ul>",
        "research": "<ul><li>Biochemical engineering and biotechnology (synthetic biology, systems biology, biopharmaceuticals)</li><li>Advanced materials processing and nanomaterials</li><li>Biomolecular engineering and biomedical engineering</li><li>Chemical reaction engineering and catalysis</li><li>Soft matter and complex fluids (polymers, colloids, glasses)</li><li>Energy and sustainability (biofuels, carbon capture, solar)</li><li>Process systems engineering and control</li><li>Transport phenomena and fluid mechanics</li><li>Computational molecular science</li><li>Engineered nanomaterials and interfaces</li><li>Interdisciplinary with Cornell BME, Materials Science, and Bioinformatics</li></ul>",
        "source": '<a href="https://courses.cornell.edu/programs/chemical-engineering-phd/" target="_blank">Cornell Courses: Chemical Engineering PhD (Fall deadline Dec 15; no spring; GRE not required; 3 LOR; video essay required; CV; TOEFL/IELTS; cbe-gfa@cornell.edu; 607-255-4550; 152 Olin Hall)</a> | <a href="https://www.engineering.cornell.edu/cbe/phd-program/phd-admission-requirements/" target="_blank">Cornell CBE PhD Admission Requirements (online application via Graduate School; field: Chemical Engineering, Ph.D.; admission based on academic merit; completed applications by Jan 7 automatically considered for financial aid; full tuition waiver + 9-month stipend + health insurance)</a> | <a href="https://courses.cornell.edu/programs/chemical-engineering-phd/chemical-engineering-phd.pdf" target="_blank">Cornell CBE PhD Program PDF (138 credits minimum; 5 semesters minimum; Year 1: CHEME 6920, 6130, 6240; Responsible Conduct of Research; ORCID; SPR begins Year 1; A Exam Summer Year 3; CPR certification required)</a>',
    },
    "gatech-chbe-phd": {
        "school": "Georgia Institute of Technology, School of Chemical and Biomolecular Engineering",
        "en": "PhD in Chemical Engineering (also home school for PhD in Bioengineering)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.0701)",
        "dur": "~5 years full-time residential; fall primary admission; 5 core 3-credit-hour courses with minimum cumulative GPA 3.0 and minimum GPA 3.2 in the 5 core courses; qualifying exam in second semester; predoctoral review at least 6 months before thesis defense; thesis defense by Doctoral Examination Committee",
        "ddl": "Fall 2027 (August): application opens September 2026. **PhD deadline January 4, 2027**. MS deadline January 15, 2027. Fall admission only. Decisions rolling February-March; April 15 CGS reply.",
        "lang": "TOEFL iBT minimum 90 (minimum section scores 19 each) / IELTS Academic overall 7.0 (minimum band 6.5 R/L/S, 5.5 W); ETS Georgia Tech 5248; scores valid 2 years; GTLI Upper Advanced 700 Level accepted as alternative.",
        "test_cls": "GRE PER DEPARTMENT POLICY (Georgia Tech Graduate Education degree-program page lists TOEFL/IELTS as standardized tests; per broader Georgia Tech engineering PhD trend, GRE is not required; applicants should verify on current ChBE admissions page. 3 LOR; essay questions; resume; SOP; BS in engineering or science with 2 years calculus/ODE, 1 year calculus physics, 1 year chemistry preferred).",
        "tui": "All Georgia Tech ChBE PhD students receive financial assistance through departmental RA/TA and fellowships (tuition + stipend + health insurance). Typical program ~5 years. Fall-only admission; on-campus residential. ChBE also home school for Bioengineering PhD (joint with BME).",
        "overview": "The Georgia Tech School of Chemical and Biomolecular Engineering (ChBE), established in 1901, offers PhD and MS degrees in Chemical Engineering and participates in the PhD in Bioengineering as a home school (along with BME). The PhD requires 5 core 3-credit-hour courses with a minimum cumulative GPA of 3.0 and a minimum GPA of 3.2 in the 5 core courses. PhD students must take and pass the qualifying exam in their second semester. Prior to thesis defense, a predoctoral review with the committee must occur at least six months before the defense; the defense itself is conducted by a Doctoral Examination Committee chosen by the student and thesis advisor. Typical program length is about five years. All PhD students receive financial assistance through the school. The ChBE PhD deadline is January 4, 2027 (MS deadline January 15). Fall admission only.",
        "requirements": "<ul><li>Bachelor's degree in engineering or science (BS in engineering preferred; 2 years calculus/ODE, 1 year calculus-based physics, 1 year chemistry preferred, 1 semester biology preferred)</li><li>GRE per current ChBE department policy (Georgia Tech Graduate Education page lists TOEFL/IELTS; applicants should verify GRE status on current ChBE admissions page)</li><li>TOEFL iBT 90 (minimum section 19 each) / IELTS Academic 7.0 (minimum band 6.5 R/L/S, 5.5 W); ETS 5248; GTLI Upper Advanced 700 Level accepted as alternative</li><li>Georgia Tech Office of Graduate Education online application</li><li>Essay questions</li><li>3 letters of recommendation</li><li>Resume</li><li>Statement of Purpose</li><li>**PhD deadline January 4, 2027**; MS deadline January 15, 2027</li><li>Fall-only admission; on-campus residential (Atlanta, GA)</li><li>5 core 3-credit-hour courses; minimum cumulative GPA 3.0; minimum GPA 3.2 in core courses</li><li>Qualifying exam in second semester</li><li>Predoctoral review at least 6 months before thesis defense</li></ul>",
        "research": "<ul><li>Biotechnology and bioengineering (catalysis for bioprocesses, biomedicine, cancer diagnostics)</li><li>Complex systems and process systems engineering</li><li>Energy and sustainability (biofuels, solar, CO2 capture, sustainable development)</li><li>Materials and nanotechnology (polymers, microelectronics, microfluidics, MEMS)</li><li>Reaction kinetics and catalysis</li><li>Complex fluids and soft matter</li><li>Separations and purification</li><li>Thermodynamics and statistical mechanics</li><li>Environmental engineering and air quality</li><li>Pulp and paper engineering (unique ChBE strength)</li><li>Optimization and process control</li><li>Bioinformatics and computational biology</li><li>Bioengineering PhD (joint home school with BME)</li></ul>",
        "source": '<a href="https://grad.gatech.edu/degree-programs/chemical-and-biomolecular-engineering" target="_blank">Georgia Tech Graduate Education: Chemical and Biomolecular Engineering (MS Jan 15; PhD Jan 4; Fall admission; TOEFL 90 min 19/section; IELTS 7.0 min band 6.5 R/L/S, 5.5 W; ETS 5248; 3 LOR; essay; resume; SOP; research areas: biotechnology, complex systems, energy/sustainability, materials/nanotech)</a> | <a href="https://catalog.gatech.edu/programs/chemical-engineering-phd/chemical-engineering-phd.pdf" target="_blank">Georgia Tech Catalog: Chemical Engineering PhD (5 core 3-credit-hour courses; minimum cumulative GPA 3.0; minimum GPA 3.2 in core; qualifying exam in second semester; predoctoral review 6 months before defense; defense by Doctoral Examination Committee)</a> | <a href="https://www.gatech.edu/academics/doctoral-degree-programs" target="_blank">Georgia Tech Doctoral Degrees list (College of Engineering includes Chemical Engineering PhD; also participates in Bioengineering PhD)</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)}")
