# -*- coding: utf-8 -*-
"""Round 252: batch add 5 Physics PhD (second tier)
- UChicago Physics PhD (Dec 14, 2026; General GRE not required; Physics GRE REQUIRED for 2026-27 cycle - TREND REVERSAL; ETS 1832; $90 fee)
- Columbia Physics PhD (Dec 3, 2026 11:59pm ET; General GRE No; Subject Recommended but not required; 3 LOR; $120 fee; 6-year full funding)
- Yale Physics PhD (Dec 15, 2026 11:59pm ET; General + Subject both Optional; TOEFL no minimum but Speaking<=25 requires summer English; ETS 3987; 170 grad students)
- Caltech Physics PhD (Dec 15; General GRE recommended but not required; Physics Subject REQUIRED for Fall 2027 cohort - TREND REVERSAL; ETS 4034; no second PhD; MS not independent)
- Cornell Physics PhD (Dec 15; General GRE not considered; Physics Subject REQUIRED for theoretical physics applicants; experimental physics not considered; TOEFL speaking min 23; ETS 2098 dept 99)
Key finding: second tier shows more trend reversals - UChicago and Caltech Physics now require Physics Subject for Fall 2027; Cornell requires PGRE only for theory track. Columbia and Yale remain the most lenient (General No/Optional; Subject recommended/optional).
"""
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": "uchicago-physics-phd",
        "s": "uchicago",
        "n": "物理博士",
        "en": "PhD in Physics (University of Chicago, Physical Sciences Division, Department of Physics; research spans experimental and theoretical physics; located in Chicago, IL; separate from the Department of Astronomy and Astrophysics which has its own December 1 deadline and GRE-optional policy)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Chicago, IL); Autumn (Fall) admission only",
        "ddl": "Autumn 2027 matriculation: **Deadline December 14, 2026** (Physics Recruitment portal). Note: UChicago Astronomy PhD (Department of Astronomy and Astrophysics) has separate December 1, 2026 11:59pm EST deadline and GRE-optional policy - this entry is Physics, NOT Astronomy. Application fee $90 (may be waived per PSD criteria).",
        "lang": "TOEFL iBT or IELTS Academic required for non-native English speakers per UChicagoGRAD policy. ETS institution code 1832. Department code not required for Physics.",
        "test": {"cls": "TREND REVERSAL - PHYSICS GRE REQUIRED FOR 2026-2027 CYCLE; GENERAL GRE NOT REQUIRED (UChicago Physics Recruitment: 'The Physics GRE will be required for the 2026-2027 PhD admissions cycle. The General GRE will not be required. Application deadline is December 14, 2026.' 3 LOR; Statement of Purpose; CV; transcripts.)"},
        "tui": "UChicago Physical Sciences Division typically offers multi-year fully-funded support to admitted Physics PhD students, including full tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, UChicago Century Fellowship, etc.).",
        "url": "details/uchicago-physics-phd.html",
    },
    {
        "id": "columbia-physics-phd",
        "s": "col",
        "n": "物理博士",
        "en": "PhD in Physics (Columbia University, Graduate School of Arts and Sciences, Department of Physics; all students accepted for graduate study are usually assumed to be candidates for the PhD degree; located in New York, NY; separate from Applied Physics in the School of Engineering and separate from Chemical Physics subcommittee)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; three years of physics with laboratory work; working knowledge of ordinary differential equations; preliminary and qualifying exams; dissertation; on-campus residential (New York, NY); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 3, 2026, 11:59 p.m. Eastern Time**. Nonrefundable application fee $120.00. Note: Columbia Chemical Physics PhD subcommittee has separate December 2, 2026 deadline and requires GRE General - this entry is Physics, NOT Chemical Physics. Philosophical Foundations of Physics MA is a separate free-standing MA program.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test (DET) accepted for applicants whose undergraduate degree is from a country whose official language is not English. ETS institution code 2111 (Columbia GSAS).",
        "test": {"cls": "GRE GENERAL NO; PHYSICS SUBJECT RECOMMENDED BUT NOT REQUIRED (Columbia GSAS: 'Submission of GRE scores is allowed but not required; the choice is yours. We recognize that there are a variety of reasons why a student may not submit a GRE score... we will give full consideration to all applications, with or without Physics GRE scores; in particular there will be no preselection based on GRE scores prior to the holistic review.' GSAS dashboard: 'GRE General: No; GRE Subject: Recommended but not required.' 3 LOR; Statement of Academic Purpose must include grades and textbooks for highest-level courses in Mechanics, E&M, Statistical Mechanics, and Quantum Mechanics; Personal Statement; Resume.)"},
        "tui": "Columbia Physics doctoral students normally receive annual prevailing stipend and appropriate tuition, health fees, university service and support fees, and if applicable, international fees, for six years, provided they remain in good academic standing and discharge pedagogical or research duties.",
        "url": "details/columbia-physics-phd.html",
    },
    {
        "id": "yale-physics-phd",
        "s": "yale",
        "n": "物理博士",
        "en": "PhD in Physics (Yale University, Graduate School of Arts and Sciences, Department of Physics; 37 primary faculty + 29 secondary faculty = 66 total; 170 graduate students enrolled Aug 2026; located in New Haven, CT; separate from Applied Physics which has its own December 15 deadline)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; Year 1 core courses PHYS 5000/5060/5080/5020/5100/5120; written qualifying exams end of August Year 1 and Year 2; research prospectus August Year 3; advance to candidacy September Year 4; dissertation; on-campus residential (New Haven, CT); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 11:59 p.m. Eastern Time**. Applications open around September 15, 2026. Fee waiver request deadline January 2, 2027. Offer acceptance deadline April 15, 2027. Note: Yale Applied Physics PhD has separate December 15, 2026 deadline - this entry is Physics, NOT Applied Physics.",
        "lang": "TOEFL iBT required for applicants whose native language is not English. **No minimum TOEFL score for the Physics PhD program**; however, the Graduate School requires incoming doctoral students who scored 25 or below on TOEFL Speaking section or 7.5 or below on IELTS Speaking section to participate in a Summer English Language program at Yale in August prior to matriculation. ETS institution code 3987 (Yale Graduate School; no department code needed).",
        "test": {"cls": "GRE GENERAL OPTIONAL; PHYSICS SUBJECT OPTIONAL (Yale Physics: 'General GRE and Physics GRE scores are OPTIONAL for 2027 PhD program applications... All applications are reviewed holistically, and preference will not be given to students who do or do not submit GRE scores.' ETS 3987; no department code. 3 LOR; Statement of Academic Purpose; CV; transcripts; Program-Specific Questions.)"},
        "tui": "Yale Physics students receive fully subsidized tuition, a generous stipend, and free health insurance. Physics students are expected to serve as teaching fellows for four terms as part of their professional development; many students choose to continue teaching past requirements. Multi-year support through RA/TA/fellowship.",
        "url": "details/yale-physics-phd.html",
    },
    {
        "id": "caltech-physics-phd",
        "s": "caltech",
        "n": "物理博士",
        "en": "PhD in Physics (California Institute of Technology, Division of Physics, Mathematics and Astronomy, Department of Physics; MS is not normally awarded unless en route to PhD; located in Pasadena, CA; separate from Applied Physics in Engineering and Applied Science; students interested in astrophysical problems may also be considered for the Astronomy PhD)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; two written candidacy exams attempted by end of Year 1 and passed by end of Year 2; oral candidacy exam by end of Year 3 (12th term); thesis; final oral examination; on-campus residential (Pasadena, CA); Fall admission only; students must respond to offer by April 15",
        "ddl": "Fall 2027: **Deadline December 15, 2026** (Caltech Academic Catalog: 'The application submission deadline for physics is December 15'). Admission decisions typically sent in February-March; students must respond to offer by April 15.",
        "lang": "TOEFL iBT / IELTS Academic / PTE / Duolingo accepted per Caltech Graduate Studies Office policy. ETS institution code 4034. Self-reported scores accepted.",
        "test": {"cls": "TREND REVERSAL - GRE GENERAL RECOMMENDED BUT NOT REQUIRED; PHYSICS SUBJECT REQUIRED FOR FALL 2027 COHORT (Caltech Physics: 'Important graduate admissions update for applicants to the Fall 2027 cohort: The GRE general test is recommended and the GRE physics subject test is required. GRE general test scores are not a required component of the application. But for applicants who decide to submit GRE general scores, they will be considered in our evaluations.' Note: Caltech Math PhD is General Not Accepted and Subject not considered - Physics has reverted to required Subject. The physics department does not usually consider applicants who already possess a PhD. The M.S. degree is not necessary for admission.)"},
        "tui": "Caltech typically offers multi-year guaranteed support to admitted Physics PhD students independent of domestic/international status, including full tuition, monthly stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, Caltech Fellowship, etc.).",
        "url": "details/caltech-physics-phd.html",
    },
    {
        "id": "cornell-physics-phd",
        "s": "cornell",
        "n": "物理博士",
        "en": "PhD in Physics (Cornell University Graduate School, Department of Physics; field offers both Experimental Physics and Theoretical Physics concentrations; located in Ithaca, NY; separate from School of Applied and Engineering Physics (AEP) which has its own PhD program; separate from Astronomy and Space Sciences which has December 1 deadline)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Minimum 6 semesters; Q exam must be taken in second semester and fully passed by end of fourth semester; A Exam (candidacy) Spring of Year 3; B Exam (dissertation defense) Spring of Year 7; on-campus residential (Ithaca, NY); Fall admission only (no spring admission)",
        "ddl": "Fall 2027: **All application materials received by Cornell no later than December 15, 2026**. The Physics Department will not accept materials, changes, or updates after the deadline. Note: Cornell Astronomy and Space Sciences PhD has separate December 1, 2026 deadline and asks please do not submit GRE scores; Cornell Applied Physics PhD has separate December 15 deadline and does not consider GRE - this entry is Physics, NOT Astronomy, NOT Applied Physics.",
        "lang": "TOEFL iBT required for non-native English speakers. **Physics Department requires minimum speaking subscore 23** (higher than Graduate School minimum). IELTS minimum overall band 7.0; **Physics Department requires IELTS speaking subscore 7.0**. ETS institution code 2098; department code 99 (Undecided). International students offered admission as TAs must also meet ACTFL intermediate-high oral proficiency at Cornell upon matriculation.",
        "test": {"cls": "GRE GENERAL NOT CONSIDERED; PHYSICS SUBJECT REQUIRED FOR THEORETICAL PHYSICS APPLICANTS ONLY (Cornell Physics: 'The physics GRE is required for applicants with interests in theoretical physics, which includes theoretical astrophysics, theoretical elementary particle physics, and theoretical condensed matter physics. Theory applications without a physics GRE score cannot be considered for admission... The physics GRE will not be considered for applicants with interests in experimental physics or physics education research. The general GRE will not be considered for any applicants.' No cutoff score; theory applicants who feel their score does not reflect their knowledge may discuss discrepancy in personal statement. 3 LOR; Statement of Purpose; Personal Statement; transcripts.)"},
        "tui": "Cornell Physics typically offers multi-year fully-funded support to admitted PhD students, including tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, Cornell Fellowship, etc.).",
        "url": "details/cornell-physics-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> Second batch of Physics PhD sweep (UChicago, Columbia, Yale, Caltech, Cornell). Key finding: second tier shows more trend reversals. UChicago Physics now REQUIRES Physics GRE for 2026-2027 cycle (General not required). Caltech Physics now REQUIRES Physics Subject for Fall 2027 cohort (General recommended but not required) - note Caltech Math PhD is General Not Accepted and Subject not considered, so Physics policy diverges from Math policy. Cornell Physics requires Physics Subject ONLY for theoretical physics applicants (theoretical astrophysics, theoretical elementary particle physics, theoretical condensed matter); experimental physics and physics education research do not consider PGRE; General GRE not considered for any applicant. Columbia Physics remains most lenient: General No, Subject recommended but not required, no preselection based on GRE. Yale Physics: both General and Subject optional, holistic review, preference not given to students who do or do not submit scores. Important distinctions: (1) UChicago Physics (Dec 14, PGRE required) is NOT the same as UChicago Astronomy (Dec 1, GRE optional). (2) Columbia Physics (Dec 3, General No, Subject recommended) is NOT the same as Columbia Chemical Physics subcommittee (Dec 2, General Yes) or Philosophical Foundations of Physics MA. (3) Yale Physics (Dec 15, both optional) is NOT the same as Yale Applied Physics (Dec 15, separate). (4) Caltech Physics (Dec 15, Subject required) is NOT the same as Caltech Math (General Not Accepted, Subject not considered) or Caltech Applied Physics. (5) Cornell Physics (Dec 15, theory PGRE required) is NOT the same as Cornell Astronomy (Dec 1, please do not submit GRE) or Cornell Applied Physics (Dec 15, does not consider GRE).
</div>
</body>
</html>
"""

PAGES = {
    "uchicago-physics-phd": {
        "school": "University of Chicago, Physical Sciences Division, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus (Chicago, IL); Autumn admission only",
        "ddl": "Autumn 2027 matriculation: **Deadline December 14, 2026**. Fee $90 (may be waived per PSD criteria). Note: UChicago Astronomy has separate Dec 1, 2026 deadline and GRE-optional policy.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers. ETS institution 1832; no department code required for Physics.",
        "test_cls": "TREND REVERSAL - PHYSICS GRE REQUIRED FOR 2026-2027 CYCLE; GENERAL GRE NOT REQUIRED (UChicago Physics Recruitment: 'The Physics GRE will be required for the 2026-2027 PhD admissions cycle. The General GRE will not be required.')",
        "tui": "Multi-year fully-funded: full tuition + stipend + health insurance through RA/TA/fellowship (NSF GRFP, UChicago Century Fellowship).",
        "overview": "The University of Chicago Department of Physics offers the Doctor of Philosophy (PhD) degree through the Physical Sciences Division. Applications for Autumn 2027 matriculation are now open. The application deadline is December 14, 2026. CRITICAL POLICY: For the 2026-2027 PhD admissions cycle, the Physics GRE will be required. The General GRE will not be required. This is a policy change - UChicago Math PhD (Dec 3 deadline) lists General optional but Math Subject strongly encouraged with explanation if not submitted, while UChicago Physics has moved to required Subject. The application fee is $90; fee waivers are available based on PSD criteria. Applicants may contact the Physical Sciences Division Dean of Students for fee waiver questions. The Department of Physics is located in Chicago, Illinois. IMPORTANT: UChicago Astronomy PhD (Department of Astronomy and Astrophysics) is a separate program with a December 1, 2026 11:59pm EST deadline and GRE-optional (scores may be submitted optionally) policy - this entry is for Physics, NOT Astronomy. Required application materials include: online application, Statement of Purpose, three letters of recommendation, transcripts, CV/Resume, and English proficiency exam scores for international applicants. The department code for TOEFL submission to UChicago is not required for Physics; use institution code 1832. The Physical Sciences Division also hosts the Pritzker School of Molecular Engineering (PME), the Department of Statistics, the Department of Computer Science, and the James Franck Institute - Physics PhD students may collaborate with these units.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>**Physics GRE REQUIRED for 2026-2027 PhD admissions cycle** (trend reversal)</li><li>General GRE NOT required</li><li>TOEFL iBT or IELTS Academic required for non-native English speakers</li><li>ETS institution code 1832; no department code for Physics</li><li>UChicago online application (physicsrecruitment.psd.uchicago.edu)</li><li>Statement of Purpose</li><li>Three letters of recommendation</li><li>Transcripts</li><li>CV/Resume</li><li>Application fee $90 (may be waived per PSD criteria)</li><li>**Deadline December 14, 2026**</li><li>Autumn (Fall) admission only</li><li>On-campus residential (Chicago, IL)</li><li>Separate from UChicago Astronomy (Dec 1, GRE optional)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics (including LIGO collaboration)</li><li>Astrophysics (separate Astronomy PhD program)</li><li>Atomic, molecular, and optical physics</li><li>Biophysics (interdisciplinary with UChicago Biology, Pritzker School of Molecular Engineering)</li><li>Plasma physics and fusion science</li><li>Quantum information science</li><li>Mathematical physics and string theory</li><li>Interdisciplinary research with Enrico Fermi Institute, James Franck Institute, and other UChicago centers</li></ul>",
        "source": '<a href="https://physicsrecruitment.psd.uchicago.edu/apply/" target="_blank">UChicago Physics Recruitment Apply (Autumn 2027 open; Physics GRE required for 2026-27 cycle; General GRE not required; deadline December 14, 2026; fee waivers available)</a> | <a href="https://astrophysics.uchicago.edu/academics/graduate-programs/how-to-apply/" target="_blank">UChicago Astronomy How to Apply (separate program; Dec 1, 2026 11:59pm EST; GRE not required but may be submitted optionally; TOEFL 90 min / IELTS 7.0 min; ETS 1832 dept 61; fee $90)</a> | <a href="https://grad.uchicago.edu/" target="_blank">UChicagoGRAD (graduate admissions policy; English proficiency requirement; TOEFL/IELTS accepted)</a> | <a href="https://physics.uchicago.edu/" target="_blank">UChicago Department of Physics (research areas; faculty; graduate program overview)</a>',
    },
    "columbia-physics-phd": {
        "school": "Columbia University, Graduate School of Arts and Sciences, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; three years of physics with laboratory work; working knowledge of ODEs; en route MA + MPhil; dissertation; on-campus (New York, NY); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 3, 2026, 11:59 p.m. ET**. Fee $120. Note: Columbia Chemical Physics subcommittee Dec 2, General Yes; Philosophical Foundations of Physics MA is separate free-standing MA.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test accepted for non-English BA holders. ETS institution code 2111 (Columbia GSAS).",
        "test_cls": "GRE GENERAL NO; PHYSICS SUBJECT RECOMMENDED BUT NOT REQUIRED (GSAS: 'Submission of GRE scores is allowed but not required; the choice is yours... we will give full consideration to all applications, with or without Physics GRE scores; no preselection based on GRE scores prior to holistic review.')",
        "tui": "Six years of prevailing stipend + tuition + health fees + university service/support fees + international fees, provided good standing and discharge of duties.",
        "overview": "The Columbia University Graduate School of Arts and Sciences (GSAS) offers the Doctor of Philosophy (PhD) in Physics through the Department of Physics. All students accepted for graduate study in the Physics Department are usually assumed to be candidates for the PhD degree. The fall admission deadline is December 3, 2026 at 11:59 p.m. Eastern Time. The nonrefundable application fee is $120.00. The department requires three years of physics with laboratory work in fundamental college courses, and a working knowledge of ordinary differential equations. Students who have not had sufficient laboratory experience have the opportunity to register for the laboratory course (PHYS G4051) in their first year of residence. CRITICAL POLICY: Submission of GRE scores is allowed but not required; the choice is yours. Columbia GSAS recognizes that there are a variety of reasons why a student may not submit a GRE score, including expense and difficulty traveling to the test site. Therefore, the department will give full consideration to all applications, with or without Physics GRE scores; in particular there will be no preselection based on GRE scores prior to the holistic review of all application materials. The GSAS dashboard for Physics lists: GRE General: No; GRE Subject: Recommended but not required. In addition to the general GSAS requirements, the Statement of Academic Purpose should include the grades obtained and the textbooks used for the highest level courses taken in Mechanics, Electromagnetism, Statistical Mechanics, and Quantum Mechanics, and should address the question: What was your most interesting research experience, either in class, in the lab, or at work? What made it interesting? Three letters of recommendation are required; at least two must be from academic recommenders. Resume is required; writing sample is not required. The PhD program includes en route MA (typically Year 1) and MPhil (typically Year 4). The department is located in Pupin Physics Laboratories and the Schapiro Center for Engineering and Physical Science Research. Columbia Physics PhD is a separate program from Applied Physics in the School of Engineering; applications cannot be transferred between programs after submission. The Chemical Physics subcommittee (joint with Chemistry) has a separate December 2, 2026 deadline and requires GRE General - this entry is Physics, NOT Chemical Physics. The Philosophical Foundations of Physics MA is a separate free-standing MA program.",
        "requirements": "<ul><li>Bachelor's degree in physics or related field</li><li>Three years of fundamental undergraduate physics courses with laboratory work</li><li>Working knowledge of ordinary differential equations</li><li>GRE General: No (not required)</li><li>GRE Physics Subject: Recommended but not required</li><li>No preselection based on GRE scores prior to holistic review</li><li>TOEFL iBT / IELTS Academic / Duolingo accepted for non-English BA holders</li><li>ETS institution code 2111 (Columbia GSAS)</li><li>Columbia GSAS online application</li><li>Statement of Academic Purpose (must include grades and textbooks for highest-level courses in Mechanics, E&M, Statistical Mechanics, Quantum Mechanics; address most interesting research experience)</li><li>Personal Statement</li><li>Resume/CV (required)</li><li>Three letters of recommendation (at least two from academic recommenders; up to four allowed)</li><li>Transcripts from all post-secondary institutions</li><li>Application fee $120 (fee waiver available for financial need/personal hardship)</li><li>**Deadline December 3, 2026, 11:59 p.m. ET**</li><li>Fall admission only</li><li>En route MA (Year 1) + MPhil (Year 4) + PhD</li><li>Separate from Applied Physics (SEAS) and Chemical Physics subcommittee</li><li>On-campus residential (New York, NY)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics (lasers, superconductivity, solid-state physics, atomic physics, nanoscale science)</li><li>Theoretical condensed matter physics</li><li>High energy particle physics and relativistic heavy ion physics</li><li>Astrophysics and cosmology</li><li>Atomic, molecular, and optical physics</li><li>Biological physics (interdisciplinary with Columbia Microbiology, Brain Behavior)</li><li>Mathematical physics</li><li>Interdisciplinary research with Nevis Laboratories, Columbia Astrophysics Laboratory, and other centers</li></ul>",
        "source": '<a href="https://www.gsas.columbia.edu/content/physics" target="_blank">Columbia GSAS: Physics (PhD; deadline Dec 3, 2026; GRE General No; GRE Subject Recommended but not required; 3 LOR; Resume required; Writing Sample No; Statement of Academic Purpose must include grades/textbooks for highest-level courses)</a> | <a href="https://www.physics.columbia.edu/content/applying-columbia-physics-graduate-program" target="_blank">Columbia Physics Applying (Dec 3, 2026; $120 fee; three years of physics with lab; ODE knowledge; separate from Applied Physics; six-year funding; fee waiver available; no transfer between programs)</a> | <a href="https://www.gsas.columbia.edu/content/admissions-deadlines" target="_blank">Columbia GSAS Admissions Deadlines (Physics PhD Fall 12/3/2026; Astronomy PhD Fall 12/2/2026; Chemical Physics PhD Fall 12/2/2026; Philosophy Foundations of Physics MA Fall 4/22/2027)</a> | <a href="https://www.gsas.columbia.edu/content/chemical-physics" target="_blank">Columbia Chemical Physics (separate PhD subcommittee; Dec 2, 2026; GRE General Yes; only for PhD aspirants; no free-standing MA)</a>',
    },
    "yale-physics-phd": {
        "school": "Yale University, Graduate School of Arts and Sciences, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; core courses Year 1; written qualifying exams end of Aug Year 1 and Year 2; prospectus Aug Year 3; candidacy Sept Year 4; dissertation; on-campus (New Haven, CT); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 11:59 p.m. ET**. Applications open ~September 15, 2026. Fee waiver request Jan 2, 2027. Offer acceptance April 15, 2027. Note: Yale Applied Physics separate program.",
        "lang": "TOEFL iBT required for non-native English speakers. No minimum TOEFL for Physics PhD; below 25 Speaking or 7.5 IELTS Speaking requires Summer English Language program. ETS 3987 (no dept code).",
        "test_cls": "GRE GENERAL OPTIONAL; PHYSICS SUBJECT OPTIONAL (Yale Physics: 'General GRE and Physics GRE scores are OPTIONAL for 2027 PhD program applications... All applications are reviewed holistically, and preference will not be given to students who do or do not submit GRE scores.')",
        "tui": "Fully subsidized tuition + generous stipend + free health insurance; 4 terms of teaching fellowship required; multi-year support through RA/TA/fellowship.",
        "overview": "The Yale University Department of Physics offers the Doctor of Philosophy (PhD) through the Yale Graduate School of Arts and Sciences. The 2027 application period is now open. Applications are accepted from around September 15, 2026. The deadline for applications received by December 15, 2026 is 11:59 p.m. Eastern Time. CRITICAL POLICY: General GRE and Physics GRE scores are OPTIONAL for 2027 PhD program applications. All applications are reviewed holistically, and preference will not be given to students who do or do not submit GRE scores. The department has 37 primary faculty, 29 secondary faculty, totaling 66 faculty. There are 170 graduate students enrolled as of August 2026 (34% female, 64% male, 2% non-binary; 62% domestic, 38% international). Required application materials include: online application, Statement of Academic Purpose, three letters of recommendation, academic history/transcripts, Program-Specific Questions, Additional Questions (all optional), Languages, Test Scores (GRE optional; TOEFL required for non-native speakers), Resume/CV, Background, and Certificate of Statement. For English proficiency, there is no minimum TOEFL score for the Physics PhD program. However, the Graduate School requires incoming doctoral students who received a score of 25 or below on the TOEFL Speaking section, or a 7.5 or below on IELTS Speaking section, to participate in a Summer English Language program at Yale in August prior to matriculation. These students are required to demonstrate English proficiency before they are permitted to teach. ETS institution code is 3987 (Yale Graduate School); no department code is needed. Unofficial scores will not be accepted. Yale Physics students receive fully subsidized tuition, a generous stipend, and free health insurance. Physics students are expected to serve as teaching fellows for four terms as part of their professional development; depending on lab funding, some students may teach more. The program timeline: Year 1 core courses PHYS 5000/5060/5080 (fall) and PHYS 5020/5100/5120 (spring), with pass-out exams; Year 1 end August written qualifying exam (Classical Mechanics & E&M on Monday Aug 31, Quantum Mechanics & Statistical Mechanics on Tuesday Sept 1); Year 2 end August written qualifying exam for Year 2 courses; Year 3 August confirm primary advisor, begin formal research, form prospectus committee, submit research prospectus; Year 4 September advance to candidacy, October prospectus presentation; Year 5+ dissertation defense. Yale Applied Physics PhD is a separate program with its own December 15, 2026 deadline - this entry is Physics, NOT Applied Physics.",
        "requirements": "<ul><li>Bachelor's degree in physics or related field</li><li>GRE General Test Optional (not required for 2027 cycle)</li><li>GRE Physics Subject Test Optional (not required for 2027 cycle)</li><li>Holistic review; no preference given to students who do or do not submit GRE scores</li><li>TOEFL iBT required for non-native English speakers</li><li>No minimum TOEFL score for Physics PhD</li><li>Below 25 TOEFL Speaking or 7.5 IELTS Speaking requires Summer English Language program at Yale</li><li>Must demonstrate English proficiency before permitted to teach</li><li>ETS institution code 3987; no department code needed</li><li>Unofficial scores not accepted</li><li>Yale GSAS online application</li><li>Statement of Academic Purpose</li><li>Three letters of recommendation</li><li>Resume/CV</li><li>Transcripts/Academic History</li><li>Program-Specific Questions</li><li>Additional Questions (all optional)</li><li>Application fee (fee waiver request deadline January 2, 2027)</li><li>**Deadline December 15, 2026, 11:59 p.m. ET**</li><li>Fall admission only</li><li>Offer acceptance deadline April 15, 2027</li><li>Separate from Yale Applied Physics</li><li>On-campus residential (New Haven, CT)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics and cosmology (separate Astronomy PhD program)</li><li>Atomic, molecular, and optical physics</li><li>Biophysics (interdisciplinary with Yale Systems Biology, Microbial Sciences)</li><li>Nuclear physics</li><li>Quantum information science</li><li>Interdisciplinary research with Yale Wright Laboratory, Yale Center for Astronomy and Astrophysics, and other centers</li></ul>",
        "source": '<a href="https://physics.yale.edu/graduate-program/application-information" target="_blank">Yale Physics Application Information (Dec 15, 2026 deadline; General + Physics GRE Optional for 2027; holistic review; no preference given; applications open ~Sept 15, 2026)</a> | <a href="https://physics.yale.edu/prospective-graduate-student-faq" target="_blank">Yale Physics Prospective FAQ (170 grad students; 66 faculty; TOEFL required; no minimum score; below 25 Speaking requires summer English; ETS 3987; no department code; unofficial scores not accepted)</a> | <a href="https://physics.yale.edu/graduate-program/important-dates-and-deadlines" target="_blank">Yale Physics Important Dates (Year 1 core courses; written qualifying exams Aug 31-Sept 1; prospectus Year 3; candidacy Year 4; dissertation defense Year 5+)</a> | <a href="https://gsas.yale.edu/admissions/phdmasters-application-process/dates-deadlines" target="_blank">Yale GSAS Dates & Deadlines (Physics Dec 15, 2026; Applied Physics Dec 15, 2026; fee waiver Jan 2, 2027; offer acceptance April 15, 2027)</a>',
    },
    "caltech-physics-phd": {
        "school": "California Institute of Technology, Division of Physics, Mathematics and Astronomy, Department of Physics",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; two written candidacy exams by end of Year 2; oral candidacy by end of Year 3 (12th term); thesis; final oral exam; on-campus (Pasadena, CA); Fall admission only; response by April 15",
        "ddl": "Fall 2027: **Deadline December 15, 2026** (Caltech Academic Catalog). Decisions sent Feb-Mar; students must respond by April 15. Note: Caltech Math PhD has separate policy (General Not Accepted, Subject not considered) - Physics policy diverges.",
        "lang": "TOEFL iBT / IELTS Academic / PTE / Duolingo accepted per Caltech Graduate Studies Office. ETS 4034. Self-reported scores accepted.",
        "test_cls": "TREND REVERSAL - GRE GENERAL RECOMMENDED BUT NOT REQUIRED; PHYSICS SUBJECT REQUIRED FOR FALL 2027 COHORT (Caltech Physics: 'For applicants to the Fall 2027 cohort: The GRE general test is recommended and the GRE physics subject test is required. GRE general test scores are not a required component of the application. But for applicants who decide to submit GRE general scores, they will be considered in our evaluations.')",
        "tui": "Multi-year guaranteed support independent of domestic/international: full tuition + monthly stipend + health insurance through RA/TA/fellowship (NSF GRFP, Caltech Fellowship).",
        "overview": "The California Institute of Technology (Caltech) Department of Physics, within the Division of Physics, Mathematics and Astronomy (PMA), offers the Doctor of Philosophy (PhD) degree. The program prepares students for careers in scientific research or research combined with teaching; the most important part is independent research. A Master of Science degree may be awarded upon completion of a program of courses, but students are not normally admitted to work toward the M.S. in physics unless they are also working toward a PhD. CRITICAL POLICY UPDATE for Fall 2027 cohort: The GRE general test is recommended and the GRE physics subject test is required. GRE general test scores are not a required component of the application, but for applicants who decide to submit GRE general scores, they will be considered in the evaluations. This is a notable divergence from Caltech Math PhD (which lists General Not Accepted and Subject not considered). The application submission deadline for physics is December 15. The Caltech Physics Graduate Admissions Committee reviews applications and makes recommendations for admission to the Graduate Studies Office; the official offer of admission comes from the Graduate Studies Office via email through the online application system. Students must respond to offers by April 15. Applicants interested in astrophysical problems will also be considered for admission to the Astronomy PhD program. The physics department does not usually consider applicants who already possess a PhD. The M.S. degree is not necessary for admission; most applicants expect the B.S. or B.A. degree to be awarded after the offer of admission, but an official transcript documenting the award of an undergraduate degree is required prior to enrollment. The undergraduate preparation expected is: Mechanics at the level of Goldstein's Classical Mechanics; electromagnetism at the level of Reitz and Milford's Foundations of Electromagnetic Theory; atomic and nuclear physics at the level of R.B. Leighton's Modern Physics; introductory quantum mechanics at the level of Dicke and Wittke's Introduction to Quantum Mechanics; and advanced calculus at the level of T.M. Apostol's Mathematical Analysis. Degree requirements: Ph 242 (Physics Seminar) taken by all students in Year 1; two written candidacy exams attempted by end of Year 1 and passed by end of Year 2; Advanced Physics requirement completed by end of Year 2 (may extend to Year 3); oral candidacy exam by end of Year 3 (12th term); thesis describing independent research; final oral examination on the thesis and research. There are no foreign language requirements for a PhD in physics. Caltech Applied Physics is a separate department within Engineering and Applied Science; research overlap exists but PhDs are awarded by home department.",
        "requirements": "<ul><li>Bachelor's degree (B.S. or B.A.) in physics or related field</li><li>**Physics Subject Test REQUIRED for Fall 2027 cohort** (trend reversal)</li><li>GRE General Test recommended but not required (submitted scores will be considered)</li><li>No minimum GPA stated; holistic review</li><li>Department does NOT usually consider applicants who already possess a PhD</li><li>MS is not normally awarded unless en route to PhD</li><li>Undergraduate preparation expected: Mechanics (Goldstein), E&M (Reitz/Milford), Atomic/Nuclear (Leighton), Intro QM (Dicke/Wittke), Advanced Calculus (Apostol)</li><li>TOEFL iBT / IELTS Academic / PTE / Duolingo accepted</li><li>Self-reported scores accepted</li><li>ETS institution code 4034</li><li>Caltech Graduate Studies Office online application</li><li>Statement of Purpose</li><li>Three letters of recommendation</li><li>Transcripts</li><li>CV/Resume</li><li>**Deadline December 15, 2026**</li><li>Fall admission only</li><li>Must respond to offer by April 15</li><li>No foreign language requirement for PhD</li><li>Separate from Caltech Math, Applied Physics, and Astronomy</li><li>On-campus residential (Pasadena, CA)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics and quantum electronics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics (including CERN, LHC collaborations)</li><li>Astrophysics (students may also be considered for Astronomy PhD)</li><li>Atomic, molecular, and optical physics</li><li>Biophysics (interdisciplinary with Caltech Biology, Bioengineering)</li><li>Physics of fluids</li><li>Gravitational physics and experimental gravity (LIGO collaboration)</li><li>Interdisciplinary research with JPL, Owens Valley Radio Observatory, and other Caltech centers</li></ul>",
        "source": '<a href="https://physics.caltech.edu/academics/graduate-studies/information-for-applicants" target="_blank">Caltech Physics Information for Applicants (Fall 2027 cohort: GRE general recommended but not required; Physics Subject REQUIRED; no second PhD; MS not necessary; undergraduate preparation expected; Physics vs Applied Physics distinction)</a> | <a href="https://catalog.caltech.edu/current/information-for-graduate-students/special-regulations-for-graduate-options/physics-ph/" target="_blank">Caltech Catalog: Physics (Ph) (deadline December 15; written candidacy exams; oral candidacy by end of Year 3; no foreign language requirement; MS awarded upon request to PhD students; final oral exam)</a> | <a href="https://gradoffice.caltech.edu/admissions" target="_blank">Caltech Graduate Studies Office (online application; fee waivers; self-reported scores accepted; ETS 4034; response by April 15)</a> | <a href="https://www.gsas.caltech.edu/" target="_blank">Caltech PMA Division (Physics, Mathematics, Astronomy; interdisciplinary options)</a>',
    },
    "cornell-physics-phd": {
        "school": "Cornell University Graduate School, Department of Physics",
        "en": "PhD in Physics (field offers Experimental and Theoretical concentrations; separate from Applied Physics and Astronomy)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Minimum 6 semesters; Q exam second semester passed by end of fourth; A Exam Spring Year 3; B Exam Spring Year 7; on-campus (Ithaca, NY); Fall admission only (no spring)",
        "ddl": "Fall 2027: **All materials received by December 15, 2026**. No materials/changes/updates after deadline. Note: Cornell Astronomy Dec 1, please do not submit GRE; Cornell Applied Physics Dec 15, does not consider GRE - this entry is Physics, NOT Astronomy, NOT Applied Physics.",
        "lang": "TOEFL iBT required; **Physics Department requires minimum speaking subscore 23** (higher than Graduate School). IELTS overall 7.0; **Physics requires IELTS speaking 7.0**. ETS 2098 dept 99. International TAs must meet ACTFL intermediate-high at Cornell upon matriculation.",
        "test_cls": "GRE GENERAL NOT CONSIDERED; PHYSICS SUBJECT REQUIRED FOR THEORETICAL PHYSICS APPLICANTS ONLY (Cornell Physics: 'Physics GRE required for applicants with interests in theoretical physics, which includes theoretical astrophysics, theoretical elementary particle physics, and theoretical condensed matter physics. Theory applications without PGRE cannot be considered. PGRE will not be considered for experimental physics or physics education research. General GRE will not be considered for any applicants.' No cutoff score; theory applicants may discuss discrepancy in personal statement.)",
        "tui": "Multi-year fully-funded: tuition + stipend + health insurance through RA/TA/fellowship (NSF GRFP, Cornell Fellowship).",
        "overview": "The Cornell University Department of Physics offers the Doctor of Philosophy (PhD) degree. The graduate physics program is designed to give students a strong background in the concepts and techniques of theoretical and experimental physics in preparation for careers at the most advanced level, including research, teaching, and applications. All required application materials and supporting documents must be submitted online and received by Cornell no later than December 15. The Physics Department will not accept materials, changes, or updates to the application after the deadline. In the Academic Information section of the Cornell Graduate School application, students indicate the proposed field is Physics; for major subject area/concentration, students choose Experimental Physics, Physics, or Theoretical Physics. CRITICAL POLICY - the physics GRE is required for applicants with interests in theoretical physics, which includes theoretical astrophysics, theoretical elementary particle physics, and theoretical condensed matter physics. Theory applications without a physics GRE score cannot be considered for admission. In the admissions process for theory students, the physics GRE score is used as one factor among many; there is no cutoff score. Theory students who feel their GRE score does not reflect their physics knowledge are encouraged to discuss the discrepancy in their personal statement. The physics GRE will not be considered for applicants with interests in experimental physics or physics education research. The general GRE will not be considered for any applicants. For English language, applicants must have official TOEFL scores delivered electronically to Cornell University Graduate School (Institution code 2098). Department codes are not required; if ETS requires a department code, choose 99 (Undecided). TOEFL scores must be valid as of the application deadline (scores valid for two years after test date). The Graduate School requires an overall IELTS band score of 7.0 or higher; the Physics Department requires a minimum speaking subscore of 7.0. The Physics Department also requires a minimum TOEFL speaking subscore of 23, which is higher than the Graduate School requirement. International students offered admission as teaching assistants will also be expected to meet the oral proficiency outlines from ACTFL (American Council on the Teaching of Foreign Languages) at the intermediate-high level; this test will be administered at Cornell upon matriculation. Degree milestones: Q exam must be taken in the second semester and fully passed by the end of the fourth semester; A Exam (examination for admission to candidacy) in Spring of Year 3; B Exam (defense of dissertation) in Spring of Year 7. Required courses include PHYS 6561 Electrodynamics, PHYS 6562 Statistical Physics I, PHYS 6572 Quantum Mechanics I. All admissions decisions for Fall applications are made by March; majority in February. Cornell Astronomy and Space Sciences PhD has separate December 1, 2026 deadline and asks please do not submit GRE scores; Cornell Applied Physics PhD has separate December 15 deadline and does not consider GRE - this entry is Physics, NOT Astronomy, NOT Applied Physics.",
        "requirements": "<ul><li>Bachelor's degree in physics or related field (analytical mechanics, E&M, optics/wave motion, electronics, atomic physics; advanced undergrad lab; linear algebra, differential equations, vector calculus)</li><li>**Physics GRE REQUIRED for theoretical physics applicants** (theoretical astrophysics, theoretical elementary particle physics, theoretical condensed matter)</li><li>Physics GRE NOT considered for experimental physics or physics education research applicants</li><li>No PGRE cutoff score; theory applicants may discuss score discrepancy in personal statement</li><li>**General GRE NOT considered for any applicants**</li><li>TOEFL iBT required; Physics Dept minimum speaking subscore 23</li><li>IELTS minimum overall 7.0; Physics Dept minimum speaking subscore 7.0</li><li>ETS institution code 2098; department code 99 (Undecided)</li><li>International TAs must meet ACTFL intermediate-high oral proficiency at Cornell upon matriculation</li><li>Cornell Graduate School online application</li><li>Statement of Purpose</li><li>Personal Statement</li><li>Three letters of recommendation</li><li>Transcripts (unofficial with application; official upon admission)</li><li>CV/Resume</li><li>Application fee $105 (fee waiver available for financial need)</li><li>**All materials received by December 15, 2026**</li><li>No materials/changes/updates after deadline</li><li>Fall admission only (no spring admission)</li><li>Minimum 6 semesters to degree</li><li>Q exam second semester; passed by end of fourth</li><li>A Exam Spring Year 3; B Exam Spring Year 7</li><li>Required: PHYS 6561 Electrodynamics, PHYS 6562 Statistical Physics I, PHYS 6572 Quantum Mechanics I</li><li>Separate from Cornell Astronomy (Dec 1, no GRE) and Applied Physics (Dec 15, no GRE)</li><li>On-campus residential (Ithaca, NY)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics (PGRE required)</li><li>High energy physics / particle physics (experimental and theoretical)</li><li>Theoretical astrophysics (PGRE required)</li><li>Experimental astrophysics (PGRE not considered)</li><li>Atomic, molecular, and optical physics</li><li>Biological physics (interdisciplinary with Cornell BME, Microbiology)</li><li>Physics education research (PGRE not considered)</li><li>Interdisciplinary research with Cornell Laboratory for Accelerator-based Sciences and Education (CLASSE), Cornell Center for Materials Research, and other centers</li></ul>",
        "source": '<a href="https://physics.cornell.edu/prospective-graduate-students" target="_blank">Cornell Physics Prospective Graduate Students (Dec 15 deadline; PGRE required for theoretical physics applicants only; General GRE not considered; TOEFL speaking min 23; IELTS speaking min 7.0; ETS 2098 dept 99; decisions by March)</a> | <a href="https://courses.cornell.edu/programs/physics-phd/" target="_blank">Cornell Courses: Physics PhD (6 semesters minimum; Q exam second semester passed by end of fourth; A Exam Spring Year 3; B Exam Spring Year 7; required courses PHYS 6561/6562/6572; TOEFL speaking min 23; Fall only)</a> | <a href="https://astro.cornell.edu/graduate-how-to-apply" target="_blank">Cornell Astronomy How to Apply (separate; Dec 1 deadline; General + Physics GRE not required nor accepted; please do not submit; TOEFL 600 paper / 250 computer; ETS 2098 dept 76; fee $105)</a> | <a href="https://www.engineering.cornell.edu/aep/ms-phd-admission-requirements/" target="_blank">Cornell Applied Physics Admission Requirements (separate; Dec 15; does not require and will not consider GRE; TOEFL/IELTS; fall admission; decisions by end of February)</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)}")
