# -*- coding: utf-8 -*-
"""Round 239: batch add 5 Mechanical Engineering PhD
- MIT MechE PhD (Dec 1, GRE not required except Naval Engineer; TOEFL 100 / IELTS 7.0 / DET 135)
- UIUC MechSE PhD (Dec 1 Fall, GRE not required/not reviewed; GPA 3.25 last 2 yrs)
- CMU MechE PhD (Dec 15 Fall, GRE not accepted; ~12% admit rate; full fellowship + stipend)
- GaTech ME PhD (Jan 10 Fall, GRE temporarily waived; TOEFL 94; GPA 3.3; 36 semester hours)
- UCSD MAE PhD (Dec 2 Fall, GRE optional; 36 units; DQE within first 6 quarters)
"""
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-meche-phd",
        "s": "mit",
        "n": "机械工程博士",
        "en": "PhD in Mechanical Engineering (Massachusetts Institute of Technology, MIT School of Engineering, Department of Mechanical Engineering; doctor of philosophy / doctor of science; one admission process shared by SM and PhD)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years full-time residential; fall-only (September entry); single admission process for SM and PhD (students without a master's earn SM en route to PhD); thesis proposal, general exam, thesis defense; teaching and research responsibilities",
        "ddl": "Fall 2027 (September): application opens September 15, 2026. **Deadline December 1, 2026 at 11:59 PM Eastern Time**. Early admission (currently enrolled MIT MechE seniors) deadline November 1, decisions by December 1. Application fee $90. Decisions released on or around February 15.",
        "lang": "TOEFL iBT minimum 100 / IELTS Academic 7.0 / Duolingo DET 135 (preferred IELTS); ETS MIT code 3514; English-medium undergraduate exempts; scores within 5 years; preferred IELTS, academic only.",
        "test": {"cls": "GRE NOT REQUIRED (MIT MechE: 'The GRE is NOT required except for the 2N and 2N6 Naval Engineer's degree programs.' MechE does not accept GRE scores and will not consider them in evaluation; if scores were sent in other applications, they are not visible to the review committee. 3 LOR; Statement of Objectives; CV; transcripts; core MechE undergraduate exposure expected: solid mechanics, dynamics, fluid mechanics, thermodynamics, heat transfer, materials, control, design/manufacturing, basic circuits/EM)."},
        "tui": "Full funding for admitted PhD students through research/teaching assistantships and MIT fellowships (tuition + stipend + health insurance). International students must have full financial support for the first year. Application fee $90.",
        "url": "details/mit-meche-phd.html",
    },
    {
        "id": "illinois-mechse-phd",
        "s": "illinois",
        "n": "机械工程博士",
        "en": "PhD in Mechanical Engineering (University of Illinois Urbana-Champaign, Department of Mechanical Science & Engineering, MechSE; traditional ME PhD track; students can earn MS on the way to PhD)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4-5 years full-time residential; fall (primary) and spring admissions available; direct entry from BS to PhD allowed; MS-on-way option; thesis-based research; qualifying exam; dissertation defense; 96 credit hours required if entering with MS (TAM PhD requires 96 regardless of MS)",
        "ddl": "Fall 2027 (August): **Deadline December 1, 2026**. Spring 2027 (January): deadline September 15, 2026. Application fee $70 domestic / $90 international. Decisions on rolling basis between application submission and April 15.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English; ETS UIUC code 1836; scores must be verified before department deadline; English-medium undergraduate may be exempted per Graduate College policy; recommended minimum TOEFL iBT 103, IELTS 7.0.",
        "test": {"cls": "GRE NOT REQUIRED (UIUC MechSE: 'We do not currently require the GRE for admission. You can submit your test scores with your application however we cannot guarantee that the committee will review the scores.' For Spring 2025/Fall 2025 cycle: GRE scores will not be accepted or reviewed. 3 LOR; SOP (max 3 pages); transcripts; minimum GPA 3.25/4.0 last 2 years of undergraduate; minimum 3.5/4.0 on any prior graduate work; BS in mechanical engineering or closely related field)."},
        "tui": "All on-campus MS and PhD students are automatically considered for financial support during application review (no separate funding application); support typically through RA/TA/fellowship packages covering tuition + stipend. PhD admission is strongly favored for support.",
        "url": "details/illinois-mechse-phd.html",
    },
    {
        "id": "cmu-meche-phd",
        "s": "cmu",
        "n": "机械工程博士",
        "en": "PhD in Mechanical Engineering (Carnegie Mellon University, College of Engineering, Department of Mechanical Engineering; research doctorate; typically 3-5 years to completion)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "3-5 years full-time residential; fall primary (September) and spring entry; coursework + research; qualifying exam; dissertation proposal and defense; typically enrolled full-time in Pittsburgh campus",
        "ddl": "Fall 2027 (September): **PhD deadline December 15, 2026**. MS deadline January 5, 2027. Spring 2027: MS/PhD deadline August 31, 2026. Application fee $75 (US). Supplemental materials (LOR, official test scores) may arrive after deadline.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo DET required for non-native English; waived for applicants who completed 4 years in-residence undergraduate in the US or Canada (excluding Quebec); scores within 2 years; recommended minimum TOEFL iBT 100, IELTS 7.5.",
        "test": {"cls": "GRE NOT ACCEPTED (CMU MechE: 'Official GRE scores from ETS are not accepted.' Fall 2023 onward policy. 3 LOR; Statement of Purpose (PhD applicants only); unofficial transcripts; admission rate ~12% PhD / ~35% MS; BS in mechanical engineering or related engineering/science)."},
        "tui": "Enrolled PhD students typically receive a **full-tuition fellowship and monthly stipend** (self-supported MS programs do not receive departmental aid); support through advisor research grants, teaching assistantships, and fellowships. Application fee $75 (waivers for CMU alumni, GEM, McNair scholars).",
        "url": "details/cmu-meche-phd.html",
    },
    {
        "id": "gatech-me-phd",
        "s": "gatech",
        "n": "机械工程博士",
        "en": "PhD in Mechanical Engineering (Georgia Institute of Technology, George W. Woodruff School of Mechanical Engineering; doctoral degree requires 36 semester hours of coursework beyond BS; qualifying examination within first year)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4-5 years full-time residential; fall primary (August) and spring entry; 36 semester hours of coursework (C or higher); PhD qualifying examination within first year (within 2 years for direct BS entry); dissertation proposal and defense; required ME/NRE/MP 8014 Seminar (pass/fail) and 3-hour Teaching Practicum (ME/NRE/MP 7757)",
        "ddl": "Fall 2027 (August): **PhD deadline January 10, 2027**. Spring 2027 (January): PhD deadline October 1, 2026. Application fee $85 international. International students on terminal MS typically not admitted (3 exceptions); PhD admission is the primary entry.",
        "lang": "TOEFL iBT minimum 94 (sectional minimums 19 each) / IELTS Academic 7.0; ETS Georgia Tech code R5248; English-medium undergraduate may be exempted per GTLI policy; scores within 2 years.",
        "test": {"cls": "GRE TEMPORARILY WAIVED (Georgia Tech Woodruff School: 'The requirement to take the GRE exam is temporarily waived for Spring 2023 and Fall 2023 applicants.' Current cycle continues waiver; minimum Quantitative 155 if submitted. 3 LOR; SOP; transcripts; minimum GPA 3.3/4.0 (undergraduate and graduate); BS in mechanical engineering or related engineering/science/math)."},
        "tui": "PhD students are typically supported through Woodruff School research assistantships, teaching assistantships, and fellowships (tuition + stipend). Application fee $85 international. International applicants on terminal MS generally not admitted (3 exceptions); PhD is the primary funded track.",
        "url": "details/gatech-me-phd.html",
    },
    {
        "id": "ucsd-mae-phd",
        "s": "ucsd",
        "n": "机械与航空航天工程博士",
        "en": "PhD in Mechanical and Aerospace Engineering (University of California San Diego, Jacobs School of Engineering, Department of Mechanical and Aerospace Engineering; Engineering Sciences doctorate with 8 specialization tracks)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5 years full-time residential; fall-only (September); 36 units of graduate coursework; Department Qualifying Exam (DQE) within first 6 quarters (oral, 3-person committee); Advancement to Candidacy Senate Exam before end of 4th year; dissertation defense typically by end of 5th year; MS can be obtained en route after 36 units",
        "ddl": "Fall 2027 (September): application opens September 2, 2026. **PhD deadline December 2, 2026**. MS deadline January 13, 2027. UCSD Graduate Division application. Decisions typically by early March.",
        "lang": "TOEFL iBT minimum 80 / IELTS Academic 7.0 (UCSD Graduate Division minimum); ETS UCSD code 4836; English-medium undergraduate may be exempted; recommended TOEFL iBT 100+ for competitive MAE applications.",
        "test": {"cls": "GRE OPTIONAL (UCSD MAE: 'GRE - NOT REQUIRED. If students want to submit GRE scores as a part of their application, that is acceptable. Applications are evaluated as a total package.' Self-reported unofficial scores accepted at review; official scores required only if admitted. No minimum; admitted PhD applicants typically provide quantitative GRE at 85-90th percentile and above. 3 LOR; SOP; CV; transcripts; BS in mechanical engineering or related engineering/science)."},
        "tui": "MAE PhD students typically receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance) via UCSD Graduate Division. Self-reported GRE scores may be submitted but are not required; official scores required only if matriculating.",
        "url": "details/ucsd-mae-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 Mechanical Engineering / Mechanical and Aerospace Engineering at five top-ranked U.S. engineering schools (MIT / UIUC / CMU / Georgia Tech / UCSD). 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 across the five: MIT MechE and UIUC MechSE explicitly do not require/review GRE; CMU MechE does not accept GRE scores; Georgia Tech has GRE temporarily waived; UCSD MAE is GRE-optional.
</div>
</body>
</html>
"""

PAGES = {
    "mit-meche-phd": {
        "school": "Massachusetts Institute of Technology, Department of Mechanical Engineering",
        "en": "PhD in Mechanical Engineering (PhD / ScD)",
        "deg": "Doctor of Philosophy (PhD) / Doctor of Science (ScD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1901)",
        "dur": "5-6 years full-time residential; fall-only; single admission process for SM and PhD (students without a master's earn SM en route); thesis proposal, general exam, thesis defense",
        "ddl": "Fall 2027 (Sept): opens Sept 15, 2026. **Deadline December 1, 2026 at 11:59 PM ET**. Early admission (MIT MechE seniors) Nov 1, decisions by Dec 1. Decisions ~Feb 15. Fee $90.",
        "lang": "TOEFL iBT 100 / IELTS Academic 7.0 / Duolingo DET 135 (IELTS preferred); ETS MIT 3514; English-medium exempts; scores within 5 years.",
        "test_cls": "GRE NOT REQUIRED (MIT MechE: 'The GRE is NOT required except for the 2N and 2N6 Naval Engineer's degree programs.' MechE does not accept or consider GRE scores. 3 LOR; Statement of Objectives; CV; transcripts; core MechE undergraduate exposure expected).",
        "tui": "Full funding for admitted PhD via RA/TA and MIT fellowships (tuition + stipend + health insurance). International students must have full financial support for the first year. Fee $90.",
        "overview": "The MIT Department of Mechanical Engineering offers a single graduate admission process leading to both the Master of Science (SM) and the Doctor of Philosophy (PhD) / Doctor of Science (ScD). Students admitted without a master's degree earn the SM en route to the PhD; students entering with an SM from another institution may apply directly to the PhD track. The program is fall-only (September entry) and requires a bachelor's degree in mechanical engineering or a related engineering/science discipline with undergraduate-level exposure to core MechE disciplines (solid mechanics, dynamics, fluid mechanics, thermodynamics, heat transfer, materials, control, design/manufacturing, basic circuits and electromagnetic field theory). The PhD requires a thesis proposal, general exam, and thesis defense, with research/teaching assistantship responsibilities.",
        "requirements": "<ul><li>Bachelor's degree in mechanical engineering or related engineering/science; undergraduate exposure to core MechE disciplines expected</li><li>GRE NOT required (MechE does not accept or consider GRE except for Naval Engineer's degree)</li><li>TOEFL iBT 100 / IELTS 7.0 / DET 135 (non-native English; IELTS preferred); ETS 3514; English-medium exempts</li><li>MIT online application (apply.mit.edu)</li><li>Statement of Objectives</li><li>3 letters of recommendation</li><li>Curriculum vitae</li><li>Transcripts</li><li>**Deadline December 1, 2026 at 11:59 PM ET**</li><li>Fall-only admission; on-campus residential</li><li>Application fee $90</li></ul>",
        "research": "<ul><li>Acoustics and dynamics</li><li>Aerospace engineering (aeronautics, astronautics, propulsion)</li><li>Bioengineering (biomechanics, biomedical devices, medical imaging)</li><li>Controls, robotics, and distributed systems</li><li>Design and manufacturing</li><li>Energy (combustion, heat transfer, sustainable energy systems, nuclear)</li><li>Fluid mechanics and ocean engineering</li><li>Materials science and engineering</li><li>Micro/nano-scale engineering and MEMS</li><li>Ocean science and engineering</li><li>Solid mechanics and mechanics of materials</li><li>Naval Engineer's degree (2N / 2N6) — GRE required only for this track</li></ul>",
        "source": '<a href="https://meche.mit.edu/education/prospective-students/graduate/apply" target="_blank">MIT MechE Applying for Admission (Dec 1 deadline; GRE not required except 2N/2N6 Naval Engineer; 3 LOR; SOP; transcripts; online application via apply.mit.edu)</a> | <a href="https://oge.mit.edu/programs/mechanical-engineering/" target="_blank">MIT OGE Mechanical Engineering (Dec 1 at 11:59 PM ET; fee $90; NSF GRFP Engineering; STEM eligible; TOEFL required for international; GRE not required except Naval Engineer)</a> | <a href="https://meche.mit.edu/education/prospective-students/graduate/graduate-admissions-faq" target="_blank">MIT MechE Graduate Admissions FAQ (single admission for SM/PhD; no direct PhD from BS; 3 LOR; TOEFL 100 / IELTS 7.0 / DET 135; IELTS preferred; scores within 5 years)</a>',
    },
    "illinois-mechse-phd": {
        "school": "University of Illinois Urbana-Champaign, Department of Mechanical Science & Engineering",
        "en": "PhD in Mechanical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1901)",
        "dur": "4-5 years full-time residential; fall (primary) and spring admissions; direct entry from BS to PhD allowed; MS-on-way option; thesis-based research; qualifying exam; dissertation defense",
        "ddl": "Fall 2027 (Aug): **Deadline December 1, 2026**. Spring 2027 (Jan): deadline September 15, 2026. Fee $70 domestic / $90 international. Decisions rolling between submission and April 15.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English; ETS UIUC 1836; scores must be verified before department deadline; recommended TOEFL iBT 103, IELTS 7.0.",
        "test_cls": "GRE NOT REQUIRED (UIUC MechSE: 'We do not currently require the GRE for admission... committee will not review scores.' Spring/Fall 2025: GRE scores will not be accepted or reviewed. 3 LOR; SOP max 3 pages; minimum GPA 3.25/4.0 last 2 years; 3.5/4.0 on prior graduate work; BS in ME or closely related field).",
        "tui": "All on-campus MS and PhD students are automatically considered for financial support during application review (no separate funding application); support typically through RA/TA/fellowship packages covering tuition + stipend. PhD admission strongly favored for support.",
        "overview": "The University of Illinois Urbana-Champaign Department of Mechanical Science & Engineering (MechSE) offers MS and PhD degrees in Mechanical Engineering (ME) and Theoretical and Applied Mechanics (TAM). The PhD in Mechanical Engineering is a research doctorate designed for students seeking careers in academia, national laboratories, or industrial R&D. Students may enter directly from a bachelor's degree and earn an MS on the way to the PhD, or enter with an MS. The TAM PhD track requires 96 credit hours regardless of prior MS. The program admits both fall (primary) and spring (limited) students, with funding automatically considered for all on-campus applicants through RA/TA/fellowship appointments.",
        "requirements": "<ul><li>Bachelor's degree in mechanical engineering or closely related field</li><li>Minimum GPA 3.25/4.0 in last 2 years of undergraduate; minimum 3.5/4.0 on any prior graduate work</li><li>GRE NOT required (MechSE explicitly does not require or review GRE scores)</li><li>TOEFL iBT / IELTS Academic (non-native English; scores verified before deadline); ETS 1836; recommended TOEFL 103, IELTS 7.0</li><li>UIUC Graduate College online application</li><li>Statement of Purpose (max 3 pages)</li><li>3 letters of recommendation</li><li>Transcripts</li><li>**Fall deadline December 1, 2026; Spring deadline September 15, 2026**</li><li>Fall and Spring admissions</li><li>Application fee $70 domestic / $90 international</li></ul>",
        "research": "<ul><li>Mechanics and materials (solid mechanics, dynamics, biomechanics)</li><li>Fluids and thermal sciences (fluid mechanics, heat transfer, combustion, energy systems)</li><li>Controls, robotics, and mechatronics</li><li>Design and manufacturing (CAD, micro/nano manufacturing, additive manufacturing)</li><li>Bioengineering and biomedical mechanics</li><li>Theoretical and Applied Mechanics (TAM) — separate PhD track, 96 credits</li><li>Computational science and engineering</li><li>Sustainable energy and environmental systems</li><li>Aerospace propulsion and hypersonics</li><li>Microelectromechanical systems (MEMS) and nanotechnology</li></ul>",
        "source": '<a href="https://mechse.illinois.edu/graduate/MS-PhD-FAQ" target="_blank">UIUC MechSE MS/PhD FAQ (Fall deadline Dec 1; Spring Sep 15; GRE not required; TOEFL/IELTS required; 3 LOR; SOP; decisions rolling through April 15)</a> | <a href="https://mechse.illinois.edu/graduate/MS-PhD-requirements" target="_blank">UIUC MechSE MS/PhD Requirements (GRE not currently required; TOEFL/IELTS required; ME and TAM degree options; MS-on-way option; direct BS to PhD allowed)</a> | <a href="http://catalog.illinois.edu/graduate/engineering/mechanical-engineering-phd/" target="_blank">UIUC Catalog: Mechanical Engineering PhD (minimum GPA 3.25 last 2 years; 3.5 on prior graduate work; GRE not required; TOEFL/IELTS required; Spring and Fall admissions)</a>',
    },
    "cmu-meche-phd": {
        "school": "Carnegie Mellon University, Department of Mechanical Engineering",
        "en": "PhD in Mechanical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1901)",
        "dur": "3-5 years full-time residential; fall primary (September) and spring entry; coursework + research; qualifying exam; dissertation proposal and defense; full-time Pittsburgh campus",
        "ddl": "Fall 2027 (Sept): **PhD deadline December 15, 2026**. MS deadline January 5, 2027. Spring 2027: MS/PhD deadline August 31, 2026. Fee $75 (US). Supplemental materials may arrive after deadline.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo DET required for non-native English; waived for 4-year in-residence undergraduate in US/Canada (excluding Quebec); scores within 2 years; recommended TOEFL 100, IELTS 7.5.",
        "test_cls": "GRE NOT ACCEPTED (CMU MechE: 'Official GRE scores from ETS are not accepted.' Fall 2023 onward. 3 LOR; SOP (PhD only); unofficial transcripts; admit rate ~12% PhD / ~35% MS; BS in ME or related engineering/science).",
        "tui": "Enrolled PhD students typically receive a **full-tuition fellowship and monthly stipend** (self-supported MS does not receive departmental aid); support via advisor research grants, teaching assistantships, and fellowships. Fee $75 (waivers for CMU alumni, GEM, McNair scholars).",
        "overview": "The Carnegie Mellon University Department of Mechanical Engineering (MechE) offers a research-intensive PhD in Mechanical Engineering designed for students pursuing careers in academia, national research laboratories, or industrial R&D. The program typically takes 3-5 years to complete, combining graduate coursework with dissertation research. Admission is competitive (approximately 12% PhD acceptance rate vs 35% for MS). The department admits approximately 300 full-time graduate students across MS and PhD programs. PhD students are funded through a combination of full-tuition fellowships and monthly stipends supported by faculty research grants, teaching assistantships, and external fellowships.",
        "requirements": "<ul><li>Bachelor's degree in mechanical engineering or related engineering/science</li><li>GRE NOT accepted (CMU MechE does not accept ETS GRE scores since Fall 2023)</li><li>TOEFL iBT / IELTS Academic / Duolingo DET (non-native English); waived for 4-year in-residence undergraduate in US/Canada (excluding Quebec)</li><li>CMU MechE online application</li><li>Statement of Purpose (PhD applicants only)</li><li>3 letters of recommendation</li><li>Unofficial transcripts (official required upon enrollment)</li><li>**Fall PhD deadline December 15, 2026; MS deadline January 5, 2027**</li><li>Spring entry: MS/PhD deadline August 31</li><li>Application fee $75 (US); waivers for CMU alumni, GEM, McNair scholars</li><li>Approximately 12% PhD admission rate</li></ul>",
        "research": "<ul><li>Artificial Intelligence Engineering (AI Engineering - MechE certificate)</li><li>Biomechanics and biomedical engineering</li><li>Controls, robotics, and mechatronics</li><li>Design, manufacturing, and systems engineering</li><li>Energetics, combustion, and propulsion</li><li>Fluid mechanics and aerodynamics</li><li>Materials science and engineering</li><li>Mechanics of solids and structures</li><li>MEMS and micro/nano engineering</li><li>Thermal science and energy systems</li><li>Additive manufacturing and 3D printing</li></ul>",
        "source": '<a href="https://www.meche.engineering.cmu.edu/education/graduate-programs/admission/" target="_blank">CMU MechE Graduate Admission (GRE not accepted; 3 LOR; SOP; unofficial transcripts; TOEFL/IELTS/DET; fee $75; waiver options)</a> | <a href="https://www.meche.engineering.cmu.edu/education/graduate-programs/admission/faq.html" target="_blank">CMU MechE Admission FAQ (Fall PhD Dec 15; MS Jan 5; Spring Aug 31; ~12% PhD admit; ~35% MS admit; PhD students receive full-tuition fellowship + monthly stipend)</a> | <a href="https://www.meche.engineering.cmu.edu/education/graduate-programs/phd/index.html" target="_blank">CMU MechE PhD Programs (3-5 years; research doctorate; careers in research and academia)</a>',
    },
    "gatech-me-phd": {
        "school": "Georgia Institute of Technology, George W. Woodruff School of Mechanical Engineering",
        "en": "PhD in Mechanical Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1901)",
        "dur": "4-5 years full-time residential; fall primary (August) and spring entry; 36 semester hours of coursework (C or higher); PhD qualifying exam within first year (within 2 years for direct BS entry); dissertation proposal and defense; required ME/NRE/MP 8014 Seminar (pass/fail) and 3-hour Teaching Practicum (ME/NRE/MP 7757)",
        "ddl": "Fall 2027 (Aug): **PhD deadline January 10, 2027**. Spring 2027 (Jan): PhD deadline October 1, 2026. Fee $85 international. International terminal MS students generally not admitted (3 exceptions); PhD is the primary entry.",
        "lang": "TOEFL iBT minimum 94 (sectional minimums 19 each) / IELTS Academic 7.0; ETS Georgia Tech R5248; English-medium undergraduate may be exempted per GTLI policy; scores within 2 years.",
        "test_cls": "GRE TEMPORARILY WAIVED (Georgia Tech Woodruff School: 'The requirement to take the GRE exam is temporarily waived for Spring 2023 and Fall 2023 applicants.' Current cycle continues waiver; minimum Quantitative 155 if submitted. 3 LOR; SOP; transcripts; minimum GPA 3.3/4.0 (undergraduate and graduate); BS in ME or related engineering/science/math).",
        "tui": "PhD students typically supported through Woodruff School research assistantships, teaching assistantships, and fellowships (tuition + stipend). Application fee $85 international. International terminal MS students generally not admitted (3 exceptions); PhD is the primary funded track.",
        "overview": "The Georgia Institute of Technology George W. Woodruff School of Mechanical Engineering offers a research doctorate (PhD) in Mechanical Engineering. The PhD requires 36 semester hours of graduate coursework (letter-grade, C or higher), a PhD qualifying examination typically taken within the first year of enrollment (within 2 years for direct BS entry), a dissertation proposal, and final oral defense. All PhD students must complete ME/NRE/MP 8014 Seminar (pass/fail, not counted toward the 36 credits) and a 3-hour Teaching Practicum (ME/NRE/MP 7757). Only 6 credits at the 4000-level are permitted; the remaining 30 credits must be at the 6000-level or above. The program admits both fall (primary) and spring students; PhD is the primary funded track, and international students on terminal MS are generally not admitted (3 exceptions).",
        "requirements": "<ul><li>Bachelor's degree in mechanical engineering or related engineering/science/math</li><li>Minimum GPA 3.3/4.0 (undergraduate and graduate)</li><li>GRE temporarily waived (Woodruff School continues waiver; Quant 155 minimum if submitted); ETS R5248</li><li>TOEFL iBT 94 (sectional 19 each) / IELTS 7.0 (non-native English); English-medium may be exempted per GTLI</li><li>Georgia Tech online graduate application</li><li>Statement of Purpose</li><li>3 letters of recommendation</li><li>Transcripts</li><li>**Fall PhD deadline January 10, 2027; Spring PhD deadline October 1, 2026**</li><li>Fall and Spring admissions</li><li>Application fee $85 international</li><li>36 semester hours of coursework (C or higher); 6 credits max at 4000-level; 30+ credits at 6000-level</li></ul>",
        "research": "<ul><li>Acoustics and dynamics</li><li>Automation and mechatronics</li><li>Bioengineering</li><li>Computer-aided engineering and design</li><li>Fluid mechanics</li><li>Heat transfer, combustion, and energy systems</li><li>Manufacturing (including additive manufacturing)</li><li>Mechanics of materials</li><li>Microelectromechanical systems (MEMS)</li><li>Tribology</li><li>Nuclear engineering (joint track)</li><li>Paper science and engineering (joint track)</li></ul>",
        "source": '<a href="https://grad.gatech.edu/degree-programs/mechanical-engineering" target="_blank">Georgia Tech Graduate Education: Mechanical Engineering (PhD Fall Jan 10, Spring Oct 1; TOEFL 94 with 19 sectionals; GPA 3.3; GRE temporarily waived; Quant 155; fee $85 international)</a> | <a href="https://catalog.gatech.edu/programs/mechanical-engineering-phd/mechanical-engineering-phd.pdf" target="_blank">Georgia Tech Catalog: PhD in ME (36 semester hours; qualifying exam within first year; GPA 3.3; dissertation proposal and defense; seminar + teaching practicum required)</a> | <a href="https://me.gatech.edu/sites/default/files/2024-10/PhDME-101524.pdf" target="_blank">Woodruff School PhD ME Program of Study (36 credits; Major Area 30, Minor Area 6; ME/NRE/MP 8014 Seminar; 3-hour Teaching Practicum ME/NRE/MP 7757; 6 credits max at 4000-level; MEng/MS thesis may count up to 9 credits)</a>',
    },
    "ucsd-mae-phd": {
        "school": "University of California San Diego, Department of Mechanical and Aerospace Engineering",
        "en": "PhD in Mechanical and Aerospace Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1901)",
        "dur": "5 years full-time residential; fall-only (September); 36 units of graduate coursework; Department Qualifying Exam (DQE) within first 6 quarters (oral, 3-person committee); Advancement to Candidacy Senate Exam before end of 4th year; dissertation defense typically by end of 5th year; MS can be earned en route after 36 units",
        "ddl": "Fall 2027 (Sept): application opens September 2, 2026. **PhD deadline December 2, 2026**. MS deadline January 13, 2027. UCSD Graduate Division application. Decisions typically by early March.",
        "lang": "TOEFL iBT minimum 80 / IELTS Academic 7.0 (UCSD Graduate Division minimum); ETS UCSD 4836; English-medium undergraduate may be exempted; recommended TOEFL 100+ for competitive MAE applications.",
        "test_cls": "GRE OPTIONAL (UCSD MAE: 'GRE - NOT REQUIRED. If students want to submit GRE scores as a part of their application, that is acceptable. Applications are evaluated as a total package.' Self-reported unofficial scores at review; official scores required only if admitted. No minimum; admitted PhD applicants typically provide quantitative GRE at 85-90th percentile and above. 3 LOR; SOP; CV; transcripts; BS in ME or related engineering/science).",
        "tui": "MAE PhD students typically receive full funding through departmental RA/TA and fellowships (tuition + stipend + health insurance) via UCSD Graduate Division. Self-reported GRE scores accepted at review; official scores required only if matriculating.",
        "overview": "The University of California San Diego Department of Mechanical and Aerospace Engineering (MAE) offers a research doctorate (PhD) in Engineering Sciences with eight specialization tracks. The PhD program is designed for students pursuing careers in aerospace, mechanical engineering, or related engineering sciences. Students complete 36 units of graduate coursework, pass a Department Qualifying Exam (DQE) as an oral examination by a three-person committee within the first six quarters, advance to candidacy via a Senate Exam before the end of the fourth year, and defend a dissertation by the end of the fifth year. Students may obtain an MS en route by completing the 36 units. The MAE department offers eight major codes: Aerospace Engineering (MC75), Applied Mechanics (MC76), Applied Ocean Science (MC78), Engineering Physics (MC80), Computational Engineering & Science (MC91), Power & Energy Systems (MC92), Controls & Mechatronics (MC93), and Biomechanics & Biomedical Engineering (MC94).",
        "requirements": "<ul><li>Bachelor's degree in mechanical engineering or related engineering/science</li><li>GRE OPTIONAL (MAE does not require GRE; self-reported scores accepted; no minimum; admitted PhD applicants typically provide quant GRE at 85-90th percentile+)</li><li>TOEFL iBT 80 / IELTS 7.0 (non-native English; recommended TOEFL 100+); 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</li><li>Curriculum vitae</li><li>Transcripts</li><li>**Fall PhD deadline December 2, 2026; MS deadline January 13, 2027**</li><li>Fall-only admission; on-campus residential</li><li>36 units of graduate coursework; DQE oral exam within first 6 quarters</li></ul>",
        "research": "<ul><li>Aerospace Engineering (MC75) — aerodynamics, propulsion, spacecraft systems</li><li>Applied Mechanics (MC76) — solid mechanics, materials, structural mechanics</li><li>Applied Ocean Science (MC78) — ocean engineering, coastal dynamics, hydrodynamics</li><li>Engineering Physics (MC80) — physics-based engineering, optics, energy</li><li>Computational Engineering & Science (MC91) — high-performance computing, numerical methods</li><li>Power & Energy Systems (MC92) — energy conversion, renewable energy, batteries</li><li>Controls & Mechatronics (MC93) — robotics, autonomous systems, control theory</li><li>Biomechanics & Biomedical Engineering (MC94) — biomechanics, medical devices, tissue engineering</li></ul>",
        "source": '<a href="https://mae.ucsd.edu/grad/graduate-admissions" target="_blank">UCSD MAE Graduate Admissions (PhD Dec 2, MS Jan 13; GRE NOT required but optional; self-reported scores accepted; quant 85-90th percentile typical for admitted PhD; 8 specialization tracks)</a> | <a href="https://mae.ucsd.edu/grad/phd" target="_blank">UCSD MAE Doctoral Program (5-year typical; DQE before end of 2nd year; Candidacy Senate Exam before end of 4th year; dissertation defense by end of 5th year; MS en route after 36 units)</a> | <a href="https://catalog.ucsd.edu/curric/MAE-gr.html" target="_blank">UCSD Catalog: MAE Graduate Doctoral Program (3 doctoral exams; DQE oral within first 6 quarters; 36 units of coursework; MS en route option; 8 specialization major codes MC75-MC94)</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)}")
