# -*- coding: utf-8 -*-
"""Round 226: batch add 5 Business School Economics PhD programs
- stanford-gsb-eap-phd (Stanford GSB PhD Economic Analysis & Policy)
- up-wharton-applied-econ-phd (Wharton PhD Applied Economics)
- uchicago-booth-econ-phd (Chicago Booth PhD Economics, Stevens Program)
- nu-kellogg-mecs-phd (Kellogg PhD Managerial Economics & Strategy)
- mit-sloan-applied-econ-phd (MIT Sloan PhD Applied Economics)
Key finding: Chicago Booth Economics and Kellogg MECS are GRE-ONLY (no GMAT);
Stanford GSB EAP, Wharton Applied Economics, MIT Sloan Applied Economics accept GRE or GMAT.
Deadlines: Dec 1 (Stanford GSB, MIT Sloan) vs Dec 15 (Wharton, Booth, Kellogg).
All fully funded.
"""
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": "stanford-gsb-eap-phd",
        "s": "stanford",
        "n": "经济分析与政策博士",
        "en": "PhD in Economic Analysis & Policy (Stanford Graduate School of Business)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "5-6 years full-time; small cohort; interdisciplinary with Stanford Economics department; fall-only admission",
        "ddl": "Fall 2027: December 1, 2026 (5:00pm PT). Decision by mid-February. Fall entry only. Fee $125.",
        "lang": "TOEFL or IELTS required for non-native English speakers per Stanford graduate admissions.",
        "test": {"cls": "GRE preferred, but GRE or GMAT accepted (per Stanford GSB field table: Economic Analysis & Policy = GRE preferred, accepts both). ETS code 4704. All GRE scores from Dec 1, 2021-Dec 1, 2026 must be reported (no superscore). No minimum score."},
        "tui": "Full fellowship: tuition + stipend + health insurance. Knight-Hennessy Scholars available. Research assistantships and teaching assistantships available.",
        "url": "details/stanford-gsb-eap-phd.html",
    },
    {
        "id": "up-wharton-applied-econ-phd",
        "s": "up",
        "n": "应用经济学博士",
        "en": "PhD in Applied Economics (The Wharton School, University of Pennsylvania)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; coursework + preliminary written/oral exam + dissertation proposal + oral defense; many programs require a preliminary research paper; fall-only admission",
        "ddl": "Fall 2027: December 15, 2026 (11:59pm EST). Decision by late February / early March. Fall entry only.",
        "lang": "TOEFL or IELTS required for non-native English speakers. Wharton expects high proficiency.",
        "test": {"cls": "GRE or GMAT required (both accepted for Applied Economics). No minimum score. Admitted student distribution (Fall 2026 cohort): GRE V160 / Q169 (percentiles 80 / 95) -- distribution, not minimum threshold. Tests must be taken no later than December 15."},
        "tui": "Full fellowship: tuition + living stipend + health insurance. All admitted Wharton doctoral students receive full funding.",
        "url": "details/up-wharton-applied-econ-phd.html",
    },
    {
        "id": "uchicago-booth-econ-phd",
        "s": "uchicago",
        "n": "经济学博士",
        "en": "PhD in Economics (Chicago Booth School of Business, Stevens Doctoral Program)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; coursework and exams in first 2 years; dissertation begins Year 3; fall-only admission",
        "ddl": "Fall 2027: December 15, 2026. Decisions via virtual interviews (Jan-early March); all decisions by March. Fall entry only.",
        "lang": "TOEFL iBT minimum 100 (pre-Jan 2026) / 5 overall with 5 in each subsection (on/after Jan 21, 2026); IELTS minimum 7.0 overall with 7.0 sub-scores.",
        "test": {"cls": "GRE REQUIRED (per Booth FAQ: Economics = GRE is required; GMAT NOT accepted). No minimum score. 2026-27 admitted cohort distribution: average GPA 3.91, average GRE Q168, average TOEFL 109, 52% hold an advanced degree, average age 24, 18 countries represented -- distribution, not minimum threshold. Note: Booth Finance accepts GMAT, but Economics does not."},
        "tui": "Full funding: tuition + stipend + health insurance. Stevens Doctoral Program funds all admitted students.",
        "url": "details/uchicago-booth-econ-phd.html",
    },
    {
        "id": "nu-kellogg-mecs-phd",
        "s": "nu",
        "n": "管理经济学与战略博士",
        "en": "PhD in Managerial Economics & Strategy (Kellogg School of Management, Northwestern University)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "5 years full-time; small cohort (~5 students per year); jointly offered by MEDS and Strategy departments; cross-registration with Northwestern Economics; fall-only admission",
        "ddl": "Fall 2027: December 15, 2026. Decisions late February / early March. Fall entry only. Fee $95 (dual application with Northwestern Economics PhD: $175).",
        "lang": "TOEFL or IELTS required for non-native English speakers per Northwestern graduate admissions.",
        "test": {"cls": "GRE REQUIRED (per Kellogg FAQ: Managerial Economics & Strategy = GRE required; GMAT NOT accepted). ETS code 1565 (Northwestern Graduate School). No minimum score; holistic review. Strong preparation expected: calculus, linear algebra, optimization, probability and statistics, economics. About half of entering students have a graduate degree. Writing sample optional."},
        "tui": "5-year guaranteed financial aid package: tuition + stipend + health insurance + moving allowance + computer equipment subsidy + conference travel budget.",
        "url": "details/nu-kellogg-mecs-phd.html",
    },
    {
        "id": "mit-sloan-applied-econ-phd",
        "s": "mit",
        "n": "应用经济学博士",
        "en": "PhD in Applied Economics (MIT Sloan School of Management)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; small cohort (~19 students per year across all Sloan PhD areas); fall-only admission; no distance/part-time option",
        "ddl": "Fall 2027: December 1, 2026. Fall entry only. Fee $95. No rolling admissions.",
        "lang": "TOEFL iBT minimum 90; IELTS minimum 7.0. ETS code 3510 (MIT Sloan). No waivers.",
        "test": {"cls": "GRE or GMAT required (both accepted for Applied Economics; note: Institute for Work & Employment Research and Information Technology groups require GRE only). ETS code 3510; GMAT code X5X-QS-21. No minimum score; faculty prioritize highest quantitative scores. At-home testing allowed. No test waivers."},
        "tui": "5-year guaranteed funding package: tuition + medical insurance + fellowship stipend and/or TA/RA salary + new laptop computer + conference travel/research budget.",
        "url": "details/mit-sloan-applied-econ-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> This is a research-oriented PhD program in business school economics / applied economics. Admitted PhD students receive full financial support. Admission statistics shown are distribution ranges, not minimum thresholds. Course/credit details pending department bulletin verification. STEM designation status pending department confirmation.
</div>
</body>
</html>
"""

PAGES = {
    "stanford-gsb-eap-phd": {
        "school": "Stanford Graduate School of Business",
        "en": "PhD in Economic Analysis & Policy",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "Pending department confirmation",
        "dur": "5-6 years full-time; interdisciplinary with Stanford Economics department",
        "ddl": "Fall 2027: December 1, 2026 (5:00pm PT). Fee $125. Fall only.",
        "lang": "TOEFL or IELTS required per Stanford graduate admissions.",
        "test_cls": "GRE preferred, but GRE or GMAT accepted. ETS 4704. All GRE scores from Dec 1, 2021-Dec 1, 2026 must be reported (no superscore). No minimum score.",
        "tui": "Full fellowship: tuition + stipend + health insurance. Knight-Hennessy Scholars available.",
        "overview": "Stanford GSB Economic Analysis & Policy PhD trains scholars who use economics to address public policy and business challenges. The program is interdisciplinary, with cross-registration in Stanford's Economics Department. Research spans public finance, labor economics, health economics, industrial organization, and political economy. The GSB PhD admits a cohort of 20-25 students across all 7 fields each year.",
        "requirements": "<ul><li>Bachelor's degree; strong quantitative preparation</li><li>GRE preferred (GMAT also accepted)</li><li>TOEFL or IELTS (non-native English)</li><li>Statement of purpose, resume/CV, transcripts</li><li>3 letters of reference</li><li>$125 application fee</li><li>December 1, 2026 5:00pm PT deadline</li><li>Fall entry only</li><li>No minimum GPA or GRE score</li></ul>",
        "research": "<ul><li>Public finance and taxation</li><li>Labor economics and the labor market</li><li>Health economics and health policy</li><li>Industrial organization and competition</li><li>Political economy and governance</li><li>Development economics</li><li>Economics of education</li><li>Environmental and energy economics</li></ul>",
        "source": '<a href="https://www.gsb.stanford.edu/programs/phd/fields/economic-analysis-policy" target="_blank">Stanford GSB PhD Economic Analysis & Policy</a> | <a href="https://www.gsb.stanford.edu/programs/phd/admission/application-materials/gmat-gre" target="_blank">GMAT & GRE Field Table</a> | <a href="https://applygsb.stanford.edu/apply/" target="_blank">Application Portal (Dec 1, 5pm PT)</a>',
    },
    "up-wharton-applied-econ-phd": {
        "school": "The Wharton School, UPenn",
        "en": "PhD in Applied Economics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "Pending department confirmation",
        "dur": "4-5 years full-time; coursework + preliminary exam + research paper + dissertation",
        "ddl": "Fall 2027: December 15, 2026 (11:59pm EST). Fall only.",
        "lang": "TOEFL or IELTS required; high proficiency expected.",
        "test_cls": "GRE or GMAT required (both accepted). No minimum score. Fall 2026 admitted distribution: GRE V160 / Q169 (percentiles 80 / 95) -- distribution, not minimum. Tests must be taken by December 15.",
        "tui": "Full fellowship: tuition + living stipend + health insurance. All admitted Wharton doctoral students funded.",
        "overview": "Wharton Applied Economics is part of the Graduate Group of Managerial Science and Applied Economics. The program includes business economics and public policy, real estate, and related subfields. It trains scholars for academic careers in economics departments and business schools. Full-time study only, beginning in the fall semester.",
        "requirements": "<ul><li>Bachelor's degree; strong quantitative/economics preparation</li><li>GRE or GMAT (both accepted)</li><li>TOEFL or IELTS (non-native English)</li><li>Statement of purpose, applicant history, transcripts</li><li>Letters of recommendation</li><li>December 15, 2026 11:59pm EST deadline</li><li>Fall entry only; full-time study</li><li>Preliminary research paper typically required</li></ul>",
        "research": "<ul><li>Business economics and public policy</li><li>Real estate economics and urban economics</li><li>Industrial organization</li><li>Labor economics and human resources</li><li>Health economics</li><li>International trade and finance</li><li>Public finance and taxation</li><li>Econometrics and quantitative methods</li></ul>",
        "source": '<a href="https://doctoral.wharton.upenn.edu/overview/facts-and-dates/" target="_blank">Wharton Doctoral Facts & Dates</a> | <a href="https://doctoral.wharton.upenn.edu/application-requirements/" target="_blank">Application Requirements</a> | <a href="https://doctoral.wharton.upenn.edu/faq/" target="_blank">FAQ (admitted GRE distribution)</a>',
    },
    "uchicago-booth-econ-phd": {
        "school": "Chicago Booth School of Business",
        "en": "PhD in Economics (Stevens Doctoral Program)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "Pending department confirmation",
        "dur": "4-5 years full-time; coursework/exams Year 1-2; dissertation Year 3",
        "ddl": "Fall 2027: December 15, 2026. Virtual interviews Jan-early March; decisions by March. Fall only.",
        "lang": "TOEFL iBT 100 (pre-Jan 2026) / 5 overall with 5 subsections (on/after Jan 21, 2026); IELTS 7.0 overall with 7.0 sub-scores.",
        "test_cls": "GRE REQUIRED (per Booth FAQ: Economics = GRE is required; GMAT NOT accepted). No minimum score. 2026-27 admitted distribution: avg GPA 3.91, avg GRE Q168, avg TOEFL 109, 52% advanced degree, avg age 24, 18 countries -- distribution, not minimum. Note: Booth Finance accepts GMAT, but Economics does not.",
        "tui": "Full funding: tuition + stipend + health insurance. Stevens Doctoral Program funds all admitted students.",
        "overview": "Chicago Booth PhD in Economics is one of the dissertation areas within the Stevens Doctoral Program. It trains scholars in microeconomic theory, macroeconomics, and econometrics for academic careers. The program is highly selective: about 20-25 students enter the Stevens Program across all dissertation areas each year. Booth Economics is distinct from the University of Chicago Department of Economics PhD (offered through the Division of the Social Sciences).",
        "requirements": "<ul><li>Bachelor's degree; strong economics and quantitative preparation</li><li>GRE required (GMAT NOT accepted for Economics)</li><li>TOEFL 100 / IELTS 7.0 (international)</li><li>Statement of purpose, transcripts, CV</li><li>Letters of recommendation</li><li>December 15, 2026 deadline</li><li>Fall entry only; full-time Stevens Doctoral Program</li><li>Virtual interviews for shortlisted candidates</li></ul>",
        "research": "<ul><li>Microeconomic theory</li><li>Macroeconomics and monetary economics</li><li>Econometrics and applied microeconomics</li><li>Industrial organization</li><li>Labor economics</li><li>Financial economics</li><li>International economics</li><li>Public economics</li></ul>",
        "source": '<a href="https://www.chicagobooth.edu/phd/dissertation-areas/economics" target="_blank">Chicago Booth PhD Economics</a> | <a href="https://www.chicagobooth.edu/phd/faq" target="_blank">PhD FAQ (test requirements by area)</a> | <a href="https://www.chicagobooth.edu/phd/admissions" target="_blank">Admissions (2026-27 class profile)</a>',
    },
    "nu-kellogg-mecs-phd": {
        "school": "Northwestern University Kellogg School of Management",
        "en": "PhD in Managerial Economics & Strategy",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "Pending department confirmation",
        "dur": "5 years full-time; small cohort (~5 students per year); jointly offered by MEDS and Strategy; cross-registration with Northwestern Economics",
        "ddl": "Fall 2027: December 15, 2026. Decisions late February / early March. Fall only. Fee $95 (dual with Economics PhD: $175).",
        "lang": "TOEFL or IELTS required per Northwestern graduate admissions.",
        "test_cls": "GRE REQUIRED (per Kellogg FAQ: Managerial Economics & Strategy = GRE required; GMAT NOT accepted). ETS 1565. No minimum score; holistic. Strong prep expected: calculus, linear algebra, optimization, probability and statistics, economics. About half of entering students have a graduate degree. Writing sample optional.",
        "tui": "5-year guaranteed aid: tuition + stipend + health insurance + moving allowance + computer subsidy + conference travel budget.",
        "overview": "Kellogg PhD in Managerial Economics & Strategy (MECS) is jointly offered by the Departments of Managerial Economics & Decision Sciences (MEDS) and Strategy. It emphasizes rigorous theoretical and empirical models to solve problems in economics and strategy. A small cohort (typically 5 students per year) allows early engagement in research. Graduates secure positions in economics departments and business schools worldwide. Students may also dual-apply with the Northwestern Economics PhD program ($175 fee).",
        "requirements": "<ul><li>Bachelor's degree before enrollment</li><li>GRE required (GMAT NOT accepted for MECS)</li><li>TOEFL or IELTS (non-native English)</li><li>Statement of purpose, transcripts, resume</li><li>Letters of recommendation</li><li>$95 application fee (dual Economics PhD: $175)</li><li>December 15, 2026 deadline</li><li>Fall entry only; no online/part-time</li><li>Strong preparation: calculus, linear algebra, optimization, probability & statistics, economics</li><li>Master's degree not required; ~half of entering students have a graduate degree</li></ul>",
        "research": "<ul><li>Decision theory and game theory</li><li>Industrial organization and firm strategy</li><li>Organizational economics</li><li>Political economy and formal political theory</li><li>Development economics</li><li>Health economics</li><li>Technology and innovation economics</li><li>Cross-disciplinary work with Northwestern Economics Department</li></ul>",
        "source": '<a href="https://www.kellogg.northwestern.edu/doctoral/programs/managerialeconomicsstrategy.aspx" target="_blank">Kellogg PhD MECS</a> | <a href="http://www.kellogg.northwestern.edu/admissions/phd-admissions/phd-how-to-apply/" target="_blank">How to Apply (test requirements by area)</a> | <a href="http://www.kellogg.northwestern.edu/doctoral/faqs.aspx" target="_blank">PhD FAQ</a>',
    },
    "mit-sloan-applied-econ-phd": {
        "school": "MIT Sloan School of Management",
        "en": "PhD in Applied Economics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "Pending department confirmation",
        "dur": "4-5 years full-time; small cohort (~19 students per year across all Sloan PhD areas); fall-only admission",
        "ddl": "Fall 2027: December 1, 2026. Fall only. Fee $95. No rolling admissions.",
        "lang": "TOEFL iBT minimum 90; IELTS minimum 7.0. ETS code 3510. No waivers.",
        "test_cls": "GRE or GMAT required (both accepted for Applied Economics; note: Institute for Work & Employment Research and Information Technology groups require GRE only). ETS 3510; GMAT X5X-QS-21. No minimum score; faculty prioritize highest quantitative scores. At-home testing allowed. No test waivers.",
        "tui": "5-year guaranteed funding: tuition + medical insurance + fellowship stipend and/or TA/RA salary + new laptop + conference travel/research budget.",
        "overview": "MIT Sloan PhD in Applied Economics trains scholars who use economic theory and econometrics to address practical challenges. Research spans organizations, health economics, macroeconomics, pricing, markets and industrial organization, development economics, and energy and environmental economics. The program is part of the Economics, Finance & Accounting academic area. MIT Sloan PhD admits about 19 students per year across all academic groups. Students are affiliated with research centers including MIT CEEPR (energy), MIT LFE (financial engineering), MIT Sloan HSI (health systems), and the MIT Joint Program on Science & Policy of Global Change.",
        "requirements": "<ul><li>Bachelor's degree; strong quantitative/economics preparation</li><li>GRE or GMAT required (no waivers; at-home testing allowed)</li><li>TOEFL 90 / IELTS 7.0 (international)</li><li>Research statement, transcripts, CV</li><li>Letters of recommendation</li><li>$95 application fee</li><li>December 1, 2026 deadline</li><li>Fall entry only; no distance/part-time</li><li>Note: IWER and IT groups require GRE only; Applied Economics accepts both</li></ul>",
        "research": "<ul><li>Organizational economics</li><li>Health economics and health systems</li><li>Macroeconomics and monetary economics</li><li>Industrial organization and pricing</li><li>Development economics</li><li>Energy and environmental economics (affiliated with CEEPR)</li><li>Financial economics (affiliated with LFE)</li><li>Science and policy of global change (affiliated with Joint Program)</li></ul>",
        "source": '<a href="https://mitsloan.mit.edu/programs/phd/application-information" target="_blank">MIT Sloan PhD Application Information</a> | <a href="https://mitsloan.mit.edu/faculty/academic-groups/applied-economics/about-applied-economics" target="_blank">Applied Economics Group</a> | <a href="https://mitsloan.mit.edu/programs/phd/resources-and-faqs" target="_blank">PhD Resources & FAQs (funding package)</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)}")
