# -*- coding: utf-8 -*-
"""Round 253: batch add 5 Physics PhD (third tier)
- UCSD Physics PhD (Dec 16, 2026 5pm PST; General optional/not used; Physics Subject RECOMMENDED; ETS 4836; fee domestic $135 intl $155)
- UMich Physics PhD (Dec 15, 11:59pm EST; General not required per Rackham; fee $75/$90; ETS 1839 dept 0808; separate from Applied Physics Jan 15)
- UCLA Physics PhD (Dec 15, 2026; General accepted but not required; Physics Subject strongly recommended per 2027-28 catalog; ETS 4837 dept 0808; PhD only - MAT/MS suspended; separate from Astronomy & Astrophysics and PBM)
- CMU Physics PhD (Dec 15; fee only $25; General or Subject recommended if available but not required; TOEFL 86/IELTS 6.5/DET 110; separate from Applied Physics; new Astronomy & Astrophysics PhD pending university approval)
- UIUC Physics PhD (Jan 15, 2027; General and Physics Subject both optional; ETS 1836; 20 semester hrs intermediate/advanced physics; GPA 3.0 min but below 3.5 rarely admitted; 96 hours; qual by start of third semester; TOEFL speaking 24+ / IELTS 8+ / TSE 50+ for TA)
Key finding: third tier is largely GRE-free/recommended (UCSD recommends Subject; UCLA strongly recommends Subject; CMU recommends if available; UMich and UIUC fully optional). UIUC has the latest deadline (Jan 15, 2027) in this sweep.
"""
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": "ucsd-physics-phd",
        "s": "ucsd",
        "n": "物理博士",
        "en": "PhD in Physics (UC San Diego, Department of Physics; located in La Jolla, CA; offers specializations including Computational Science PY79 via CSME; separate from Astronomy PhD and separate from Physics and Biology in Medicine interdepartmental program)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; 7 core courses (PHYS 200A, 201, 203A-B, 210A, 212A-B); advanced graduate courses; teaching requirement; PhD candidacy exam; final thesis defense; on-campus residential (La Jolla, CA); Fall admission only",
        "ddl": "Fall 2027 (2027-28 cycle): **Deadline December 16, 2026 at 5:00 p.m. PST**. Application opens September 2, 2026 at 12 p.m. PST. Application fee: domestic $135.00, international $155.00. Note: UCSD Astronomy PhD is separate; UCSD Physics and Biology in Medicine (PBM) is interdepartmental in Graduate Programs in Bioscience.",
        "lang": "TOEFL iBT or IELTS Academic required for non-native English speakers per UCSD Graduate Division. ETS institution code 4836. Self-reported scores accepted for initial review; official scores required upon admission.",
        "test": {"cls": "GRE GENERAL OPTIONAL AND NOT USED IN ADMISSION DECISIONS; PHYSICS SUBJECT GRE RECOMMENDED (UCSD Physics: 'The General GRE will not be used in our admission decisions. The Physics Subject GRE is recommended for all applicants to the Physics PhD program. We strongly recommend that applicants submit a physics GRE score with their applications, if circumstances allow. This will provide an opportunity for students who have taken the physics GRE to demonstrate abilities that might not be apparent elsewhere in their application. No application will be penalized or placed at a disadvantage by not reporting Physics or General GRE scores.' 3 LOR; Statement of Purpose; transcripts; CV.)"},
        "tui": "UCSD Physics typically offers multi-year fully-funded support to admitted PhD students, including full tuition, stipend, and health insurance through a combination of Research Assistantships, Teaching Assistantships, and fellowship awards (NSF GRFP, Eugene Cota-Robles Fellowship, etc.).",
        "url": "details/ucsd-physics-phd.html",
    },
    {
        "id": "umich-physics-phd",
        "s": "umich",
        "n": "物理博士",
        "en": "PhD in Physics (University of Michigan, College of Literature, Science, and the Arts, Department of Physics; Rackham Graduate School; located in Ann Arbor, MI; separate from the Applied Physics Program which has its own January 15 deadline and requires General GRE)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; dissertation; on-campus residential (Ann Arbor, MI); Fall admission only (no spring admission); supplementary materials accepted through January 3",
        "ddl": "Fall 2027: **Deadline December 15, 11:59 p.m. EST**. Online application system disabled at deadline. Supplementary materials (LORs, transcripts) accepted through January 3. Application fee: $75 for US citizens/permanent residents, $90 for non-US citizens. Note: UMich Applied Physics Program PhD has separate January 15 deadline and requires General GRE - this entry is Physics, NOT Applied Physics.",
        "lang": "TOEFL iBT or IELTS Academic required for non-native English speakers per Rackham Graduate School English proficiency guidelines. ETS institution code 1839 (Rackham); department code 0808 (Physics).",
        "test": {"cls": "GRE GENERAL NOT REQUIRED PER RACKHAM POLICY (Rackham Tests: 'GRE general test scores are no longer included in the admissions process for Rackham doctoral programs.' Physics Subject not listed as required; holistic review per LSA Physics. 3 LOR; Statement of Purpose; Personal Statement; transcripts; CV.)"},
        "tui": "UMich Physics PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and Rackham/NSF fellowships, including full tuition, stipend, and health insurance.",
        "url": "details/umich-physics-phd.html",
    },
    {
        "id": "ucla-physics-phd",
        "s": "ucla",
        "n": "物理博士",
        "en": "PhD in Physics (University of California, Los Angeles, Department of Physics and Astronomy, Physics Division; located in Los Angeles, CA; PhD only - MAT and MS suspended indefinitely; separate from Astronomy and Astrophysics division and separate from Physics and Biology in Medicine interdepartmental program)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; core courses; written and oral qualifying exams; candidacy; dissertation; on-campus residential (Los Angeles, CA); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026**. Fall quarter only. Note: UCLA Astronomy and Astrophysics PhD has separate December 15, 2026 deadline; UCLA Physics and Biology in Medicine (PBM) interdepartmental PhD has separate December 1, 2026 deadline and GRE not required - this entry is Physics, NOT Astronomy, NOT PBM.",
        "lang": "TOEFL iBT or IELTS Academic required for non-native English speakers. ETS institution code 4837; department code 0808 (Physics). TOEFL scores may also be sent to department code 76 (Physics); IELTS to department and institution.",
        "test": {"cls": "GRE GENERAL ACCEPTED BUT NOT REQUIRED; PHYSICS SUBJECT STRONGLY RECOMMENDED (grad.ucla.edu 2027-2028 catalog: 'GRE: Subject in Physics is strongly recommended. GRE General exam will be accepted but is not required.' Department page: 'Students who wish to apply for admission to our graduate program for the 2026-2027 academic year are not required to take the GRE or submit a GRE score report as part of their application package. However, students may voluntarily submit GRE test scores and they will be reviewed as part of the holistic application consideration. The applications with GRE scores will not be given greater weight than those that do not include scores.' 3 LOR; Statement of Purpose; transcripts.)"},
        "tui": "UCLA Physics PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and fellowships (NSF GRFP, UCLA Dissertation Year Fellowship, etc.), including tuition, stipend, and health insurance.",
        "url": "details/ucla-physics-phd.html",
    },
    {
        "id": "cmu-physics-phd",
        "s": "cmu",
        "n": "物理博士",
        "en": "PhD in Physics (Carnegie Mellon University, Mellon College of Science, Department of Physics; located in Pittsburgh, PA; small department with ~80 graduate students; offers Applied Physics PhD degree option; Astronomy and Astrophysics PhD in final stages of university approval)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "At least 4 years of full-time graduate study; minimum 1 year full-time at CMU; qualifying examination; teaching requirement; candidacy; dissertation; on-campus residential (Pittsburgh, PA); Fall admission only (no spring)",
        "ddl": "Fall 2027: **Deadline December 15, 2026**. Online application typically opens late August to early September. Application fee: $25 (very low; no waiver except GEM Fellowship applicants). Note: CMU Applied Physics PhD is a separate degree option within the Physics Department; CMU Astronomy and Astrophysics PhD is in final stages of university approval as of 2025-26.",
        "lang": "TOEFL iBT minimum composite 86 (subscores Reading/Listening/Writing minimum 22); IELTS minimum composite 6.5; Duolingo English Test (DET) minimum overall 110 (subscores: Literacy, Comprehension, Conversation, Production). Non-native English speakers must pass International Teaching Assistant (ITA) test administered by Intercultural Communication Center (ICC) before performing required classroom teaching.",
        "test": {"cls": "GRE GENERAL OR GRE PHYSICS SUBJECT RECOMMENDED IF AVAILABLE BUT NOT REQUIRED (CMU Physics FAQ: 'GRE General or GRE Subject Test scores are recommended if available but not required.' 3 LOR; Personal Statement; prior research activities; research interests; transcripts.)"},
        "tui": "CMU Physics PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and fellowships, including tuition, stipend, and health insurance. Service as TA or RA is part of graduate training and required of all candidates.",
        "url": "details/cmu-physics-phd.html",
    },
    {
        "id": "uiuc-physics-phd",
        "s": "illinois",
        "n": "物理博士",
        "en": "PhD in Physics (University of Illinois Urbana-Champaign, Department of Physics; Graduate College; located in Urbana, IL; 96 hours of course work including research units; qualifying examination by beginning of third semester; Fall admission only)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Approximately 4-5 years; 96 hours of course work (including at least 6 hours of PHYS 599 Thesis Research); qualifying exam by beginning of third semester; research; dissertation defense; on-campus residential (Urbana, IL); Fall admission only (no spring admission)",
        "ddl": "Fall 2027: **Deadline January 15, 2027** (latest in this sweep; all materials including LORs and official score reports must be received by this date; incomplete applications after January 15 not considered).",
        "lang": "TOEFL iBT or IELTS Academic required for non-native English speakers per Graduate College minimum. ETS institution code 1836 (used for both TOEFL and GRE). For teaching assistantship eligibility: TOEFL speaking subscore 24+ OR IELTS academic speaking subscore 8+ OR TSE 50+ OR University of Illinois English Proficiency Interview (EPI) score 4CP+.",
        "test": {"cls": "GRE GENERAL OPTIONAL; PHYSICS SUBJECT OPTIONAL (UIUC Physics: 'Both the Graduate Record Examination (GRE) General Tests (Verbal, Quantitative, and Analytical) and the GRE Physics Subject Test are optional this year. If you decide to submit GRE scores, please fill in your GRE registration number and test scores on the online application form AND have your official GRE Score Report sent directly from ETS to the Department of Physics by the application deadline.' 3 LOR; Statement of Purpose; transcripts.)"},
        "tui": "UIUC Physics PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and fellowships (NSF GRFP, University of Illinois Graduate Fellowship, etc.), including tuition, stipend, and health insurance. Most students with half-time assistantships take 9 hours per semester plus 4-9 hours in summer.",
        "url": "details/uiuc-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> Third batch of Physics PhD sweep (UCSD, UMich, UCLA, CMU, UIUC). Key finding: third tier is largely GRE-free/recommended. UCSD Physics Subject recommended but General not used in admission decisions; UCLA Physics Subject strongly recommended per 2027-28 catalog while General accepted but not required; CMU recommends GRE General or Subject if available but not required (and application fee is only $25); UMich General not required per Rackham doctoral policy; UIUC both General and Subject optional and has the latest deadline in this sweep (January 15, 2027). Important distinctions: (1) UCSD Physics (Dec 16) is NOT the same as UCSD Astronomy (separate) or UCSD Physics and Biology in Medicine (interdepartmental, Dec 1). (2) UMich Physics (Dec 15) is NOT the same as UMich Applied Physics Program (Jan 15, requires General GRE). (3) UCLA Physics (Dec 15) admits only PhD (MAT/MS suspended); NOT the same as UCLA Astronomy and Astrophysics (Dec 15, separate) or UCLA Physics and Biology in Medicine (interdepartmental, Dec 1, GRE not required). (4) CMU Physics (Dec 15, $25 fee) offers Applied Physics degree option within the department; Astronomy and Astrophysics PhD is pending university approval. (5) UIUC Physics (Jan 15) requires 20 semester hours of intermediate/advanced undergraduate physics; minimum GPA 3.0 but below 3.5 rarely admitted; TA eligibility requires TOEFL speaking 24+ / IELTS 8+ / TSE 50+.
</div>
</body>
</html>
"""

PAGES = {
    "ucsd-physics-phd": {
        "school": "UC San Diego, 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; 7 core courses; advanced graduate courses; teaching requirement; PhD candidacy exam; final thesis defense; on-campus (La Jolla, CA); Fall admission only",
        "ddl": "Fall 2027 (2027-28 cycle): **Deadline December 16, 2026 at 5:00 p.m. PST**. Application opens September 2, 2026 at 12 p.m. PST. Fee: domestic $135, international $155.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers. ETS institution 4836. Self-reported scores accepted for initial review.",
        "test_cls": "GRE GENERAL OPTIONAL AND NOT USED IN ADMISSION DECISIONS; PHYSICS SUBJECT GRE RECOMMENDED (UCSD Physics: 'The General GRE will not be used in our admission decisions. The Physics Subject GRE is recommended for all applicants. We strongly recommend that applicants submit a physics GRE score with their applications, if circumstances allow. No application will be penalized or placed at a disadvantage by not reporting Physics or General GRE scores.')",
        "tui": "Multi-year fully-funded: full tuition + stipend + health insurance through RA/TA/fellowship (NSF GRFP, Eugene Cota-Robles Fellowship).",
        "overview": "The UC San Diego Department of Physics offers the Doctor of Philosophy (PhD) degree. The online graduate application for 2027-28 opens on September 2, 2026 at 12 p.m. PST. The application deadline for 2027-28 is December 16, 2026 at 5 p.m. PST. CRITICAL POLICY: The General GRE will not be used in admission decisions. The Physics Subject GRE is recommended for all applicants to the Physics PhD program. The department strongly recommends that applicants submit a physics GRE score with their applications, if circumstances allow, because this provides an opportunity for students who have taken the physics GRE to demonstrate abilities that might not be apparent elsewhere in their application. However, no application will be penalized or placed at a disadvantage by not reporting Physics or General GRE scores. The application fee is $135.00 for domestic applicants and $155.00 for international applicants. Entering graduate students are required to have a sound knowledge of undergraduate mechanics, electricity, and magnetism; to have had senior courses or their equivalent in atomic and quantum physics, nuclear physics, and thermodynamics; and to have taken upper-division laboratory work. An introductory course in solid-state physics is desirable. Entering graduate students must take an entrance diagnostic exam on undergraduate physics covering mechanics, electricity and magnetism, quantum mechanics, and statistical mechanics and mathematical methods. Students who are found to have serious weaknesses in preparation will be directed to enroll in appropriate undergraduate upper-division courses. There is no foreign language requirement. PhD students are required to pass seven core courses: PHYS 200A Theoretical Mechanics I, PHYS 201 Mathematical Methods in Physics, PHYS 203A-B Advanced Classical Electrodynamics I and II, PHYS 210A Equilibrium Statistical Mechanics, PHYS 212A-B Quantum Mechanics I and II. A Specialization in Computational Science (PY79) is available: students must apply and be admitted into the PhD program in physics, and then be admitted to the CSME program. UCSD Astronomy PhD is a separate program; UCSD Physics and Biology in Medicine (PBM) is an interdepartmental program in the Graduate Programs in Bioscience with a separate December 1, 2026 deadline and GRE not required - this entry is Physics, NOT Astronomy, NOT PBM.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>Sound knowledge of undergraduate mechanics, E&M; senior courses in atomic/quantum physics, nuclear physics, thermodynamics; upper-division lab work</li><li>Introductory solid-state physics desirable</li><li>Entrance diagnostic exam on undergraduate physics (mechanics, E&M, QM, stat mech, math methods)</li><li>GRE General: optional but NOT used in admission decisions</li><li>GRE Physics Subject: strongly recommended (no penalty if not submitted)</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers</li><li>ETS institution code 4836</li><li>Self-reported scores accepted for initial review; official required upon admission</li><li>UCSD Graduate Division online application</li><li>Statement of Purpose</li><li>Three letters of recommendation</li><li>Transcripts</li><li>CV/Resume</li><li>Application fee: domestic $135, international $155</li><li>**Deadline December 16, 2026 at 5:00 p.m. PST**</li><li>Application opens September 2, 2026 at 12 p.m. PST</li><li>Fall admission only</li><li>No foreign language requirement</li><li>Specialization in Computational Science (PY79) via CSME available</li><li>Separate from UCSD Astronomy and UCSD PBM</li><li>On-campus residential (La Jolla, CA)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics (including LHC collaborations)</li><li>Astrophysics and cosmology (separate Astronomy PhD)</li><li>Atomic, molecular, and optical physics</li><li>Biological physics / biophysics</li><li>Plasma physics and fusion science</li><li>Quantum information science</li><li>Computational physics (PY79 specialization via CSME)</li><li>Interdisciplinary research with UCSD Qualcomm Institute, San Diego Supercomputer Center, and Scripps Institution of Oceanography</li></ul>",
        "source": '<a href="https://physics.ucsd.edu/students/graduate/requirements" target="_blank">UCSD Physics Admissions Requirements (2027-28: Dec 16, 2026 5pm PST; General GRE optional/not used; Physics Subject recommended; ETS 4836; fee $135/$155; application opens Sept 2, 2026)</a> | <a href="https://physics.ucsd.edu/students/graduate/degree-requirements" target="_blank">UCSD Physics Degree Requirements (7 core courses; entrance diagnostic exam; no foreign language requirement; PY79 Computational Science specialization via CSME; time limits for progress to PhD)</a> | <a href="https://catalog.ucsd.edu/graduate/degrees-offered/index.html" target="_blank">UCSD Catalog Graduate Degrees Offered (minimum 3.0 GPA upper-division; GRE program-specific; self-report allowed)</a> | <a href="https://grad.ucsd.edu/" target="_blank">UCSD Graduate Division (English proficiency; fee waivers; fellowship opportunities)</a>',
    },
    "umich-physics-phd": {
        "school": "University of Michigan, College of LSA, Department of Physics, Rackham Graduate School",
        "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 (Ann Arbor, MI); Fall admission only (no spring); supplementary materials through Jan 3",
        "ddl": "Fall 2027: **Deadline December 15, 11:59 p.m. EST**. Supplementary materials (LORs, transcripts) through January 3. Fee: $75 domestic, $90 international. Note: UMich Applied Physics Program PhD has separate January 15 deadline and requires General GRE - this entry is Physics, NOT Applied Physics.",
        "lang": "TOEFL iBT / IELTS Academic required per Rackham English proficiency guidelines. ETS institution 1839 (Rackham); department code 0808 (Physics).",
        "test_cls": "GRE GENERAL NOT REQUIRED PER RACKHAM POLICY (Rackham Tests: 'GRE general test scores are no longer included in the admissions process for Rackham doctoral programs.' Physics Subject not listed as required; holistic review per LSA Physics.)",
        "tui": "Multi-year fully-funded through RA/TA/Rackham fellowships: tuition + stipend + health insurance.",
        "overview": "The University of Michigan Department of Physics, within the College of Literature, Science, and the Arts and the Rackham Graduate School, offers the Doctor of Philosophy (PhD) degree. The Rackham Graduate School and the Department of Physics begin accepting applications for Fall admission on September 1. The application deadline is 11:59 p.m. E.S.T. on December 15. The online application system will be disabled at the deadline. The department will accept supplementary application materials (letters of recommendation, transcripts, etc.) through January 3. The application fee is $75 for United States citizens or permanent residents and $90 for non-U.S. citizens. The department has a limited number of fee waivers for domestic applicants who meet specific criteria. CRITICAL POLICY: Per Rackham Graduate School policy, GRE general test scores are no longer included in the admissions process for Rackham doctoral programs. The Physics Department does not require Physics Subject scores; the admissions committee conducts a holistic review considering academic performance to date, potential for contribution to research, and persistence in and commitment to educational success. No single factor leads to either accepting or excluding an applicant. The program of study includes coursework, preliminary and qualifying exams, and independent research leading to the dissertation. Students typically receive multi-year support through Research Assistantships, Teaching Assistantships, and Rackham or external fellowships. The University of Michigan Applied Physics Program is a separate interdisciplinary PhD program with a January 15 annual deadline and requires GRE General scores, TOEFL, SOP, Personal Statement, and three letters of recommendation - this entry is Physics, NOT Applied Physics. The department is located in Ann Arbor, Michigan. Fall admission only; there is no spring admission.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>GRE General: NOT required per Rackham doctoral policy</li><li>GRE Physics Subject: not listed as required; holistic review</li><li>TOEFL iBT / IELTS Academic required per Rackham English proficiency guidelines</li><li>ETS institution code 1839 (Rackham); department code 0808 (Physics)</li><li>Rackham Graduate School online application</li><li>Statement of Purpose</li><li>Personal Statement</li><li>Three letters of recommendation</li><li>Transcripts</li><li>CV/Resume</li><li>Application fee: $75 US citizens/permanent residents; $90 non-US citizens</li><li>Limited fee waivers for eligible domestic applicants</li><li>**Deadline December 15, 11:59 p.m. EST**</li><li>Supplementary materials accepted through January 3</li><li>Fall admission only (no spring admission)</li><li>Holistic review; no single factor determines admission</li><li>Separate from UMich Applied Physics Program (Jan 15, requires General GRE)</li><li>On-campus residential (Ann Arbor, MI)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics and materials physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics (including LHC, DUNE collaborations)</li><li>Astrophysics and cosmology</li><li>Atomic, molecular, and optical physics</li><li>Biological physics (interdisciplinary with UMich Life Sciences Institute)</li><li>Nuclear physics</li><li>Plasma physics and fusion science</li><li>Quantum information science</li><li>Interdisciplinary research with Michigan Center for Theoretical Physics, Applied Physics Program, and other centers</li></ul>",
        "source": '<a href="https://lsa.umich.edu/physics/graduate-students/application.html" target="_blank">UMich LSA Physics Applying (Dec 15, 11:59pm EST; supplementary materials through Jan 3; fee $75/$90; holistic review; no spring admission; fee waivers for eligible domestic applicants)</a> | <a href="https://rackham.umich.edu/admissions/applying/tests/" target="_blank">Rackham Tests (GRE general scores no longer included in admissions for Rackham doctoral programs; institution code 1839; scores valid 5 years; English proficiency guidelines)</a> | <a href="https://rackham.umich.edu/programs-of-study/" target="_blank">Rackham Programs of Study (Physics: Fall December 15 PhD code 00389; Applied Physics: Fall January 5 MS/PhD code 00060/00061 - separate program)</a> | <a href="https://websites.umich.edu/~appphys/doctoral.html" target="_blank">UMich Applied Physics Doctoral (SEPARATE; January 15 deadline; requires GRE General; 15 credit hours introductory/intermediate physics; ETS 1839 dept 0808)</a>',
    },
    "ucla-physics-phd": {
        "school": "University of California, Los Angeles, Department of Physics and Astronomy, Physics Division",
        "en": "PhD in Physics (PhD only; MAT and MS suspended indefinitely)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; core courses; written and oral qualifying exams; candidacy; dissertation; on-campus (Los Angeles, CA); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026**. Fall quarter only. Note: UCLA Astronomy and Astrophysics PhD has separate Dec 15 deadline; UCLA PBM interdepartmental PhD has separate Dec 1 deadline and GRE not required - this entry is Physics, NOT Astronomy, NOT PBM.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers. ETS institution 4837; department code 0808 (Physics); TOEFL scores may also go to dept code 76 (Physics).",
        "test_cls": "GRE GENERAL ACCEPTED BUT NOT REQUIRED; PHYSICS SUBJECT STRONGLY RECOMMENDED (grad.ucla.edu 2027-2028 catalog: 'GRE: Subject in Physics is strongly recommended. GRE General exam will be accepted but is not required.' Department page: 'Students are not required to take the GRE or submit a GRE score report as part of their application package. However, students may voluntarily submit GRE test scores and they will be reviewed as part of the holistic application consideration. The applications with GRE scores will not be given greater weight than those that do not include scores.')",
        "tui": "Multi-year fully-funded through RA/TA/fellowship (NSF GRFP, UCLA Dissertation Year Fellowship): tuition + stipend + health insurance.",
        "overview": "The UCLA Department of Physics and Astronomy offers the Doctor of Philosophy (PhD) in Physics through the Physics Division. Per the 2027-2028 UCLA Graduate Programs catalog, the degree is listed as 'MAT, M.S., Ph.D.' but admits only PhD applicants (MAT and MS are suspended indefinitely). The application deadline for Fall 2027 is December 15, 2026. Fall quarter only. CRITICAL POLICY: Per the UCLA Graduate Programs 2027-2028 catalog for major code 0666 (Physics): GRE Subject in Physics is strongly recommended; GRE General exam will be accepted but is not required. The department page states: students who wish to apply for admission to the graduate program for the 2026-2027 academic year are not required to take the GRE or submit a GRE score report as part of their application package. However, students may voluntarily submit GRE test scores and they will be reviewed as part of the holistic application consideration. The applications with GRE scores will not be given greater weight than those that do not include scores. Students who are admitted and intend to enroll may send official reports to UCLA institution code 4837, major code 0808 (Physics). GRE scores are accepted from tests taken within the last 5 years; if taken multiple times, enter the most recent scores on the online application. Three letters of recommendation are required. International applicants applying for financial support (fellowships, teaching and research assistantships) should have a letter of recommendation (included as one of the three required letters) which comments on their verbal ability in English. The department only considers graduate applications for the fall quarter; applications are evaluated only when all required materials are received. Both divisions (Physics and Astronomy) begin evaluating applications mid-January; offers of admission are typically made in February and March. The department is located at 430 Portola Plaza, Box 951547, Los Angeles CA 90095-1547. UCLA Astronomy and Astrophysics PhD (major code 00EB) is a separate program with a December 15, 2026 deadline and its own GRE policy (General and Subject accepted but not required; Subject in Physics strongly recommended). UCLA Physics and Biology in Medicine (PBM, major code 009Y) is an interdepartmental program in the Graduate Programs in Bioscience with a separate December 1, 2026 deadline and GRE not required - this entry is Physics, NOT Astronomy, NOT PBM.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field from accredited institution</li><li>GRE General: accepted but not required (submitted scores reviewed holistically; no greater weight given)</li><li>GRE Physics Subject: strongly recommended per 2027-2028 catalog</li><li>GRE scores valid within 5 years; most recent scores entered on application</li><li>TOEFL iBT / IELTS Academic required for non-native English speakers</li><li>ETS institution code 4837; department code 0808 (Physics); TOEFL may also go to dept code 76</li><li>UCLA Graduate Division online application</li><li>Statement of Purpose</li><li>Three letters of recommendation (at least one for international applicants seeking support should comment on English verbal ability)</li><li>Transcripts (unofficial for application review; official upon admission)</li><li>PhD only - MAT and MS suspended indefinitely</li><li>**Deadline December 15, 2026**</li><li>Fall quarter only (no winter/spring/summer admission)</li><li>Applications evaluated mid-January; offers typically February-March</li><li>Separate from UCLA Astronomy and Astrophysics (Dec 15, separate committee)</li><li>Separate from UCLA PBM interdepartmental (Dec 1, GRE not required)</li><li>On-campus residential (Los Angeles, 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 LHC, CMB-S4 collaborations)</li><li>Astrophysics and cosmology (separate Astronomy PhD division)</li><li>Atomic, molecular, and optical physics</li><li>Biological physics / medical physics (interdisciplinary with PBM)</li><li>Nonlinear dynamics and complex systems</li><li>Plasma physics and fusion science</li><li>Interdisciplinary research with UCLA California NanoSystems Institute, Institute for Pure and Applied Mathematics, and other centers</li></ul>",
        "source": '<a href="https://grad.ucla.edu/requirements/?app=admission&major=0666" target="_blank">UCLA Graduate Programs: Physics 2027-2028 (major code 0666; Dec 15, 2026; Fall only; GRE Subject in Physics strongly recommended; GRE General accepted but not required; 3 LOR; admits only PhD applicants; MAT/MS suspended)</a> | <a href="https://www.pa.ucla.edu/graduate-students.html" target="_blank">UCLA Physics & Astronomy Graduate Students (2026-2027: not required to take GRE; may voluntarily submit; reviewed holistically; no greater weight; ETS 4837 major code 0808; scores valid 5 years; fall quarter only)</a> | <a href="https://grad.ucla.edu/requirements/?app=admission&major=00EB" target="_blank">UCLA Astronomy and Astrophysics 2027-2028 (SEPARATE; major code 00EB; Dec 15, 2026; General and Subject accepted but not required; Subject in Physics strongly recommended; 3 LOR; PhD only)</a> | <a href="https://grad.ucla.edu/requirements/?app=admission&major=009Y" target="_blank">UCLA Physics and Biology in Medicine (SEPARATE; interdepartmental; major code 009Y; Dec 1, 2026; GRE not required; Graduate Programs in Bioscience)</a>',
    },
    "cmu-physics-phd": {
        "school": "Carnegie Mellon University, Mellon College of Science, Department of Physics",
        "en": "PhD in Physics (small department; ~80 graduate students; Applied Physics degree option; Astronomy and Astrophysics PhD pending university approval)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "At least 4 years full-time graduate study; minimum 1 year full-time at CMU; qualifying exam; teaching requirement; candidacy; dissertation; on-campus (Pittsburgh, PA); Fall only (no spring)",
        "ddl": "Fall 2027: **Deadline December 15, 2026**. Online application opens late August/early September. Application fee: $25 (no waiver except GEM Fellowship applicants). Note: CMU Applied Physics is a separate degree option within Physics Dept; Astronomy and Astrophysics PhD in final stages of university approval.",
        "lang": "TOEFL iBT minimum composite 86 (subscores R/L/W 22); IELTS minimum 6.5; DET minimum 110. Non-native English speakers must pass ITA test (Intercultural Communication Center) before required classroom teaching.",
        "test_cls": "GRE GENERAL OR GRE PHYSICS SUBJECT RECOMMENDED IF AVAILABLE BUT NOT REQUIRED (CMU Physics FAQ: 'GRE General or GRE Subject Test scores are recommended if available but not required.')",
        "tui": "Multi-year fully-funded through RA/TA/fellowship: tuition + stipend + health insurance. Service as TA or RA is required of all candidates.",
        "overview": "The Carnegie Mellon University Department of Physics, within the Mellon College of Science, offers the Doctor of Philosophy (PhD) in Physics. For full consideration, applications should be complete and submitted by December 15 to begin study in the fall semester of the following year. Only complete applications will receive full consideration. The application fee is $25.00; the department regrets that it is not possible to waive this small fee, with the exception of specific cases (at present for GEM Fellowship applicants only). The department is a small one: approximately 10 staff members, more than 35 faculty, approximately 20 postdocs, and more than 80 graduate students. Required application materials include: online application (typically opens late August to early September), personal statement, information about prior research activities, research interests, transcript, and letters of recommendation. CRITICAL POLICY: GRE General or GRE Subject Test scores are recommended if available but not required. For English language, minimum scores required are: TOEFL iBT / TOEFL Home composite 86 (subscores for Reading, Listening, and Writing minimum 22); IELTS / IELTS Indicator composite 6.5; Duolingo English Test (DET) overall 110 (subscores: Literacy, Comprehension, Conversation, Production). Decisions are based on the entire application record, including courses taken, GPA, letters of recommendation, research experience, and TOEFL score for non-native English speakers. The department does not offer admission for study beginning in the Spring (second) semester; the program of graduate courses and offers of financial aid are based on the full academic year beginning with the Fall semester. PhD students should expect to spend at least four years in full-time graduate study, including a minimum of one year of full-time work at Carnegie Mellon. Formal admission to candidacy depends on acceptable performance in teaching, research, and course work, as well as the Qualifying Examination. Affiliation with a research group is encouraged to happen before admission to PhD candidacy and can take place as early as the first semester; it is expected that those arrangements have been made at the latest by the end of the second year. Non-native English speakers must pass an International Teaching Assistant (ITA) test administered by the Intercultural Communication Center (ICC) before they will be allowed to perform the required classroom teaching. Beyond the conventional PhD program, Carnegie Mellon offers a degree in Applied Physics; PhD thesis research that may appropriately be characterized as Applied Physics can be carried out either within the Physics Department or in conjunction with other branches of the University such as the Robotics Institute, the Data Storage Systems Center, the Materials Science and Engineering Department, or the Electrical and Computer Engineering Department. A PhD in Astronomy and Astrophysics is currently in the final stages of University-level approval as of Summer 2025.",
        "requirements": "<ul><li>B.S., B.A., or M.S. degree in Physics or closely related subject from recognized 4-year college/university or equivalent</li><li>GRE General or GRE Physics Subject: recommended if available but not required</li><li>TOEFL iBT / TOEFL Home: minimum composite 86 (subscores R/L/W minimum 22)</li><li>IELTS / IELTS Indicator: minimum composite 6.5</li><li>Duolingo English Test: minimum overall 110</li><li>Non-native English speakers must pass ITA test (ICC) before required classroom teaching</li><li>CMU online application (opens late August/early September)</li><li>Personal Statement</li><li>Information about prior research activities and research interests</li><li>Three letters of recommendation</li><li>Transcript</li><li>Application fee: $25.00 (no waiver except GEM Fellowship applicants)</li><li>**Deadline December 15, 2026**</li><li>Fall admission only (no spring/second semester)</li><li>At least 4 years full-time graduate study; minimum 1 year full-time at CMU</li><li>Qualifying Examination required for candidacy</li><li>Research group affiliation by end of Year 2 at latest</li><li>TA/RA service required of all candidates</li><li>Applied Physics degree option within Physics Department (research may be in conjunction with Robotics Institute, DSSC, MSE, ECE)</li><li>Astronomy and Astrophysics PhD pending university approval</li><li>On-campus residential (Pittsburgh, PA)</li></ul>",
        "research": "<ul><li>Subatomic physics (CMS at LHC; KATRIN neutrino mass experiment; JLab nucleon structure)</li><li>Quantum electronics and nanophysics (including Advanced Photon Source at Argonne)</li><li>Cosmology and cosmic microwave background surveys (optical to microwave)</li><li>Biological physics (biological membrane structure at NIST)</li><li>Theoretical physics (pencil and paper, computational, ML collaboration)</li><li>Applied Physics (interdisciplinary with Robotics Institute, DSSC, MSE, ECE)</li><li>Condensed matter physics</li><li>Quantum information science</li><li>Astrophysics (pending separate Astronomy & Astrophysics PhD approval)</li></ul>",
        "source": '<a href="https://www.cmu.edu/physics/graduate-program/admission.html" target="_blank">CMU Physics Admission (Dec 15 deadline; $25 fee; no waiver except GEM; online application opens late Aug/early Sept; personal statement; prior research; research interests; transcript; LORs)</a> | <a href="https://www.cmu.edu/physics/graduate-program/faq.html" target="_blank">CMU Physics FAQ (GRE General or Subject recommended if available but not required; TOEFL 86 subscores 22; IELTS 6.5; DET 110; no spring admission; holistic review; small department ~80 grad students)</a> | <a href="https://www.cmu.edu/physics/graduate-program/index.html" target="_blank">CMU Physics Graduate Program (4+ years; minimum 1 year at CMU; Qualifying Examination; candidacy by end of Year 2; Applied Physics degree option; TA/RA service required)</a> | <a href="https://www.cmu.edu/physics/graduate-program/degree-req.html" target="_blank">CMU Physics Degree Requirements (ITA test for non-native English speakers before teaching; handbook 2025-2026; Astronomy & Astrophysics PhD pending university approval)</a>',
    },
    "uiuc-physics-phd": {
        "school": "University of Illinois Urbana-Champaign, Department of Physics, Graduate College",
        "en": "PhD in Physics (96 hours course work; qualifying exam by start of third semester; Fall admission only; January 15 deadline - latest in this sweep)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Approximately 4-5 years; 96 hours course work (including at least 6 hours PHYS 599 Thesis Research); qualifying exam by beginning of third semester; research; dissertation; on-campus (Urbana, IL); Fall admission only",
        "ddl": "Fall 2027: **Deadline January 15, 2027** (latest in this sweep; all materials including LORs and official score reports must be received by this date; incomplete applications after January 15 not considered).",
        "lang": "TOEFL iBT / IELTS Academic required per Graduate College minimum. ETS institution code 1836 (used for both TOEFL and GRE). TA eligibility: TOEFL speaking 24+ OR IELTS academic speaking 8+ OR TSE 50+ OR EPI 4CP+.",
        "test_cls": "GRE GENERAL OPTIONAL; PHYSICS SUBJECT OPTIONAL (UIUC Physics: 'Both the GRE General Tests (Verbal, Quantitative, and Analytical) and the GRE Physics Subject Test are optional this year. If you decide to submit GRE scores, please fill in your GRE registration number and test scores on the online application form AND have your official GRE Score Report sent directly from ETS to the Department of Physics by the application deadline.')",
        "tui": "Multi-year fully-funded through RA/TA/fellowship (NSF GRFP, UIUC Graduate Fellowship): tuition + stipend + health insurance. Most students with half-time assistantships take 9 hours/semester plus 4-9 hours in summer.",
        "overview": "The University of Illinois Urbana-Champaign Department of Physics offers the Doctor of Philosophy (PhD) degree through the Graduate College. The application deadline for Fall 2027 admission is January 15, 2027. All materials, including letters of recommendation and official test score reports, must be received by that date for consideration. Applications that are incomplete after January 15 are not considered. The department admits graduate students in the Fall only; there is no Spring admission. CRITICAL POLICY: Both the Graduate Record Examination (GRE) General Tests (Verbal, Quantitative, and Analytical) and the GRE Physics Subject Test are optional this year. If applicants decide to submit GRE scores, they should fill in their GRE registration number and test scores on the online application form AND have their official GRE Score Report sent directly from ETS to the Department of Physics by the application deadline. The ETS institution code is 1836 for both TOEFL and GRE. TSE (Test of Spoken English) is highly recommended if applicable. For undergraduate preparation, applicants should be on track to complete 20 semester hours of intermediate and advanced college-level physics courses (not counting introductory courses in general physics) prior to graduation. Required courses include Intermediate Electricity and Magnetism, Intermediate Mechanics, and one or (preferably) two semesters of undergraduate Quantum Mechanics. Mathematics through at least advanced calculus and differential equations is required. Courses in light and thermodynamics are highly recommended. Students who lack some prerequisite courses will still be considered for admission; if admitted, they must take the prerequisite courses at Illinois as a graduate student. The minimum GPA is 3.00 (A=4.00) for the last two years of undergraduate work; however, because of space limitations, applicants with GPAs below 3.50 are rarely admitted. Students with prior graduate course work must have a minimum GPA of 3.50 for those courses. Degree requirements: The Graduate College requires 96 hours of course work for the PhD, including research units in Physics 597 and Physics 599. Most physics students having half-time assistantships take 9 hours per semester plus 4 to 9 hours in the summer, so the total credit requirement may be fulfilled in approximately four years. At least 6 hours of PHYS 599 Thesis Research is required; most students have many more. A student must take and pass the qualifying exam by the beginning of the third semester of enrollment. For English proficiency and TA eligibility, the proficiency can be demonstrated in one of four ways: TOEFL speaking subscore 24 or above; IELTS academic speaking subscore 8 or above; TSE score 50 or above; or University of Illinois English Proficiency Interview (EPI) score 4CP or above. The department is located in Urbana, Illinois.",
        "requirements": "<ul><li>Bachelor's degree in physics, astronomy, or related field</li><li>20 semester hours of intermediate/advanced college-level physics (not counting introductory general physics)</li><li>Required: Intermediate E&M, Intermediate Mechanics, 1-2 semesters undergraduate Quantum Mechanics</li><li>Math through advanced calculus and differential equations required</li><li>Courses in light and thermodynamics highly recommended</li><li>Students missing prerequisites may be admitted but must make up courses at Illinois</li><li>Minimum GPA 3.00 (A=4.00) for last two years undergrad; below 3.50 rarely admitted due to space</li><li>Prior graduate course work: minimum GPA 3.50</li><li>GRE General: optional (submit registration number on application AND official ETS report by deadline)</li><li>GRE Physics Subject: optional (same submission requirement)</li><li>TOEFL iBT / IELTS Academic required per Graduate College minimum</li><li>ETS institution code 1836 (used for both TOEFL and GRE)</li><li>TSE highly recommended if applicable (for TA eligibility)</li><li>TA eligibility: TOEFL speaking 24+ OR IELTS academic speaking 8+ OR TSE 50+ OR EPI 4CP+</li><li>UIUC Graduate College online application</li><li>Statement of Purpose describing demonstrated potential for success in advanced physics research</li><li>Three letters of recommendation</li><li>Transcripts</li><li>**Deadline January 15, 2027** (all materials including LORs and official score reports received by this date)</li><li>Incomplete applications after January 15 not considered</li><li>Fall admission only (no spring admission)</li><li>96 hours course work for PhD (including at least 6 hours PHYS 599 Thesis Research)</li><li>Qualifying exam by beginning of third semester</li><li>On-campus residential (Urbana, IL)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics and materials physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics (including LHC collaborations)</li><li>Astrophysics and cosmology</li><li>Atomic, molecular, and optical physics</li><li>Biological physics / biophysics</li><li>Nuclear physics</li><li>Plasma physics and fusion science</li><li>Physics education research</li><li>Quantum information science</li><li>Interdisciplinary research with UIUC Materials Research Laboratory, National Center for Supercomputing Applications, and other centers</li></ul>",
        "source": '<a href="https://physics.illinois.edu/admissions/graduates/apply" target="_blank">UIUC Physics Apply (Fall 2027 deadline January 15, 2027; all materials including LORs and official score reports received by deadline; incomplete after Jan 15 not considered; Fall only; ETS 1836; TSE highly recommended)</a> | <a href="https://physics.illinois.edu/admissions/graduates/admissions-requirements" target="_blank">UIUC Physics Admissions Requirements (20 semester hrs intermediate/advanced physics; required courses Intermediate E&M/Mechanics/1-2 semesters QM; math through advanced calculus/DE; GRE General and Physics Subject optional; 3 LOR; SOP)</a> | <a href="http://catalog.illinois.edu/graduate/engineering/physics-phd/" target="_blank">UIUC Catalog: Physics PhD (minimum GPA 3.00 last two years; below 3.50 rarely admitted; prior graduate work min 3.50; GRE General and Subject optional; TOEFL/IELTS required; graduates of physical/biological sciences/math/CS may be admitted with limited standing)</a> | <a href="https://physics.illinois.edu/academics/graduates/degree-requirements" target="_blank">UIUC Physics Degree Requirements (96 hours; at least 6 hrs PHYS 599; half-time assistantships 9 hrs/semester plus 4-9 summer; qual by beginning of third semester; TA English proficiency: TOEFL speaking 24+ / IELTS 8+ / TSE 50+ / EPI 4CP+)</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)}")
