# -*- coding: utf-8 -*-
"""Round 223: batch add 5 Accounting PhD programs (Top business schools)
- up-wharton-acct-phd (Wharton PhD Accounting)
- uchicago-booth-acct-phd (Chicago Booth Stevens PhD Accounting)
- stanford-gsb-acct-phd (Stanford GSB PhD Accounting)
- nu-kellogg-acct-phd (Northwestern Kellogg PhD Accounting Information & Management)
- col-gsb-acct-phd (Columbia Business School PhD Accounting)
Pattern: all 5 require GRE or GMAT (Accounting accepts both); deadlines cluster Dec 1 (Stanford) or Dec 15 (Wharton/Booth/Kellogg/Columbia).
All are fully funded PhD programs.
"""
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": "up-wharton-acct-phd",
        "s": "up",
        "n": "会计博士",
        "en": "PhD in Accounting (Wharton School, University of Pennsylvania)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; coursework + preliminary written/oral exam + dissertation proposal and defense; fall-only admission",
        "ddl": "Fall 2027: December 15, 2026 (11:59 PM EST). All tests must be taken by Dec 15. Decisions by April 15. Full-time only; fall entry only.",
        "lang": "TOEFL iBT or IELTS required for non-native English speakers. High proficiency expected. Scores must be within 5 years.",
        "test": {"cls": "GRE or GMAT required for Accounting (both accepted). No minimum score. ETS code 2954-5199 or 2954-0000; GMAT G56-97-12. Cannot be waived. Note: Wharton Applied Economics is GRE-only, but Accounting accepts both."},
        "tui": "All admitted Wharton doctoral students receive a full fellowship: tuition + living stipend + health insurance.",
        "url": "details/up-wharton-acct-phd.html",
    },
    {
        "id": "uchicago-booth-acct-phd",
        "s": "uchicago",
        "n": "会计博士",
        "en": "Stevens Doctoral Program PhD in Accounting (Chicago Booth School of Business)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; coursework and general exam in first 2 years; dissertation begins Year 3; about 20-25 students enter Stevens Program each year across all fields",
        "ddl": "Fall 2027: December 15, 2026. You may only apply to ONE dissertation area per year. Accounting conducts virtual interviews. Fall entry only.",
        "lang": "TOEFL iBT minimum 100 (pre-Jan 21 2026) or overall 5 with 5 in each section (post-Jan 21 2026); IELTS overall 7.0 with sub-scores 7.0 each. ETS code 1819; IELTS TRF to phd@chicagobooth.edu.",
        "test": {"cls": "GRE or GMAT required for Accounting (both accepted). No exceptions; prior graduate degrees do not exempt. Average admitted GRE Quant 168 (distribution, not threshold). GRE code 1501; GMAT H9X-9F-05. Scores valid 5 years. Take test by early October for timely receipt."},
        "tui": "PhD students receive tuition grant + stipend + student health insurance + computer/subsidy + research and travel funding. 2026-27 admitted profile: avg GPA 3.91, avg GRE Q168, avg TOEFL 109, avg age 24, 52% hold advanced degrees.",
        "url": "details/uchicago-booth-acct-phd.html",
    },
    {
        "id": "stanford-gsb-acct-phd",
        "s": "stanford",
        "n": "会计博士",
        "en": "PhD in Accounting (Stanford Graduate School of Business)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "5-6 years full-time; one of seven GSB doctoral fields (Accounting / EAP / Finance / Marketing / OIT / OB / Political Economy); incoming cohort 20-25 across all fields",
        "ddl": "Fall 2027: December 1, 2026 (5:00 PM PT). Decisions by mid-March. No deferral policy. Fall entry only.",
        "lang": "TOEFL or IELTS required for non-native English speakers per Stanford graduate admissions.",
        "test": {"cls": "GRE required of all applicants (GSB general policy; field-of-study table lists Accounting as GRE preferred with GRE or GMAT accepted). ETS institutional code 4704 (no department code). For Fall 2027, accept GRE scores from Dec 1, 2021 to Dec 1, 2026. Must submit complete history of all GRE tests in range (no superscoring). Self-reported accepted pending official."},
        "tui": "Full financial fellowship: tuition + health fees + $59,500 annual living stipend (2026-27 rate). 5-6 years guaranteed funding with satisfactory academic progress. Knight-Hennessy Scholars available.",
        "url": "details/stanford-gsb-acct-phd.html",
    },
    {
        "id": "nu-kellogg-acct-phd",
        "s": "nu",
        "n": "会计信息与管理博士",
        "en": "PhD in Accounting Information & Management (Kellogg School of Management, Northwestern University)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "5 years full-time; empirical/archival and analytical/theoretical research methods; about 25 PhD students enter Kellogg each year across all programs; fall-only admission",
        "ddl": "Fall 2027: December 15, 2026. Application fee $95 (or $175 dual application with Economics PhD). Decisions late February/early March. No online/part-time.",
        "lang": "TOEFL or IELTS required for non-native English speakers. Northwestern Graduate School minimum TOEFL iBT 90 (pre-Jan 21 2026) or 4.5 (post-Jan 21 2026). ETS code 1565, dept 01.",
        "test": {"cls": "GRE or GMAT required for Accounting Information & Management (both accepted). GRE code 1565 (Northwestern Graduate School, no dept code); GMAT 6WZ-3J-54 (Kellogg PhD). No minimum score; holistic review. Recommended prior coursework: calculus, real analysis, linear algebra, optimization, probability, statistics. About half of entering students hold a graduate degree."},
        "tui": "All PhD students receive 5-year guaranteed financial aid: stipend + full tuition scholarship + annual health insurance. Incoming students also receive moving allowance, computer subsidy, and conference travel budget.",
        "url": "details/nu-kellogg-acct-phd.html",
    },
    {
        "id": "col-gsb-acct-phd",
        "s": "col",
        "n": "会计博士",
        "en": "PhD in Accounting (Columbia Business School)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; one of five CBS PhD divisions (Accounting / DRO / Finance / Management / Marketing); highly selective, fewer than 5% of applicants admitted; fall-only admission",
        "ddl": "Fall 2027: application opens September 1, 2026; deadline December 15, 2026. Application fee $100. Fall entry only.",
        "lang": "TOEFL or IELTS required unless applicant holds a degree from an institution where English was the language of instruction.",
        "test": {"cls": "GRE or GMAT required (one of the two). No minimum score. 2 letters of recommendation required (up to 4 accepted). Essay/personal statement required. Note: DRO PhD is GRE/GMAT-optional, but Accounting requires one."},
        "tui": "Fully funded by Columbia Business School: tuition + stipend + health insurance. PhD Admitted Students Day hosted for invited candidates.",
        "url": "details/col-gsb-acct-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>No (business school doctoral program)</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 at a top business school. Admitted PhD students receive full financial support. Admission statistics shown are distribution ranges, not minimum thresholds. Course/credit details pending department bulletin verification.
</div>
</body>
</html>
"""

PAGES = {
    "up-wharton-acct-phd": {
        "school": "Wharton School, UPenn",
        "en": "PhD in Accounting",
        "deg": "Doctor of Philosophy (PhD)",
        "dur": "4-5 years full-time; preliminary exam + dissertation",
        "ddl": "Fall 2027: December 15, 2026 (11:59 PM EST). Decisions by April 15.",
        "lang": "TOEFL iBT or IELTS required. High proficiency expected.",
        "test_cls": "GRE or GMAT (both accepted for Accounting). ETS 2954-5199; GMAT G56-97-12. Cannot waive.",
        "tui": "Full fellowship: tuition + stipend + health insurance for all admitted students.",
        "overview": "Wharton's PhD in Accounting is one of nine doctoral programs at the Wharton School. It combines rigorous training in accounting theory, empirical methods, and analytical modeling. The program typically takes 4-5 years and includes coursework, a preliminary written/oral exam, and a dissertation.",
        "requirements": "<ul><li>Bachelor's degree; master's not required</li><li>GRE or GMAT (Accounting accepts both)</li><li>TOEFL or IELTS (non-native English)</li><li>Letters of recommendation</li><li>Statement of purpose, applicant history, transcripts</li><li>December 15, 2026 deadline</li><li>Full-time study; fall entry only</li><li>Tests must be taken by Dec 15; send official scores by then</li></ul>",
        "research": "<ul><li>Empirical financial accounting and capital markets</li><li>Analytical/positive accounting theory</li><li>Disclosure, earnings management, and governance</li><li>Audit and assurance</li><li>Taxation and organizational decision-making</li><li>International accounting standards and regulation</li><li>Accounting-based valuation and forecasting</li></ul>",
        "source": '<a href="https://doctoral.wharton.upenn.edu/application-requirements/" target="_blank">Wharton Doctoral Application Requirements</a> | <a href="https://doctoral.wharton.upenn.edu/overview/facts-and-dates/" target="_blank">Facts & Dates</a> | <a href="https://doctoral.wharton.upenn.edu/admissions/" target="_blank">Admissions</a>',
    },
    "uchicago-booth-acct-phd": {
        "school": "Chicago Booth",
        "en": "Stevens Doctoral Program PhD in Accounting",
        "deg": "Doctor of Philosophy (PhD)",
        "dur": "4-5 years full-time; ~20-25 students enter Stevens Program each year across all fields; general exam by end of Year 2; dissertation begins Year 3",
        "ddl": "Fall 2027: December 15, 2026. Only ONE dissertation area per application year. Accounting conducts virtual interviews. Fall entry only.",
        "lang": "TOEFL iBT 100 (pre-Jan 21 2026) or 5 overall with 5 in each section (post-Jan 21 2026); IELTS 7.0 with sub-scores 7.0. ETS 1819; IELTS TRF to phd@chicagobooth.edu.",
        "test_cls": "GRE or GMAT required for Accounting (both accepted). No exceptions; prior graduate degrees do not exempt. Avg admitted GRE Quant 168 (distribution). GRE code 1501; GMAT H9X-9F-05. Take by early October for timely receipt.",
        "tui": "Tuition grant + stipend + student health insurance + computer/subsidy + research and travel funding. 2026-27 admitted profile: avg GPA 3.91, avg GRE Q168, avg TOEFL 109, avg age 24, 52% advanced degrees.",
        "overview": "The Chicago Booth Stevens Doctoral Program in Accounting trains scholars in empirical financial accounting, managerial accounting, and analytical/positive accounting theory. Students take courses across the University of Chicago in economics, statistics, and econometrics.",
        "requirements": "<ul><li>Bachelor's degree from accredited institution</li><li>GRE or GMAT required (no waiver)</li><li>TOEFL 100 / IELTS 7.0</li><li>Statement of purpose, essays, CV</li><li>Letters of recommendation</li><li>December 15, 2026 deadline</li><li>Only one dissertation area per year</li><li>Accounting conducts virtual interviews (Jan-Mar)</li><li>Fall entry only</li></ul>",
        "research": "<ul><li>Empirical financial accounting and capital markets</li><li>Analytical/positive accounting theory</li><li>Managerial accounting and internal information</li><li>Disclosure, earnings quality, and enforcement</li><li>Audit and corporate governance</li><li>Taxation and firm behavior</li><li>International accounting and regulation</li></ul>",
        "source": '<a href="https://www.chicagobooth.edu/phd/admissions/how-to-apply" target="_blank">Booth PhD How to Apply</a> | <a href="https://www.chicagobooth.edu/phd/faq" target="_blank">PhD FAQ</a> | <a href="https://www.chicagobooth.edu/phd/admissions" target="_blank">Admissions</a>',
    },
    "stanford-gsb-acct-phd": {
        "school": "Stanford Graduate School of Business",
        "en": "PhD in Accounting",
        "deg": "Doctor of Philosophy (PhD)",
        "dur": "5-6 years full-time; 20-25 students enter GSB PhD across all 7 fields each year",
        "ddl": "Fall 2027: December 1, 2026 (5:00 PM PT). Decisions by mid-March. No deferral.",
        "lang": "TOEFL or IELTS required for non-native English speakers per Stanford graduate admissions.",
        "test_cls": "GRE required of all applicants per GSB general policy (field table lists Accounting as GRE preferred, GRE or GMAT accepted). ETS code 4704. Accept scores Dec 1, 2021 - Dec 1, 2026. Must submit complete history (no superscoring). Self-reported accepted.",
        "tui": "Full fellowship: tuition + health fees + $59,500 annual living stipend (2026-27). 5-6 years guaranteed funding. Knight-Hennessy Scholars available.",
        "overview": "Stanford GSB PhD in Accounting is one of seven doctoral fields (Accounting, Economic Analysis & Policy, Finance, Marketing, Operations Information & Technology, Organizational Behavior, Political Economics). The program is designed for careers in research and teaching at leading academic institutions.",
        "requirements": "<ul><li>Bachelor's degree</li><li>GRE required (ETS 4704)</li><li>Statement of purpose, CV/education</li><li>Letters of recommendation</li><li>TOEFL or IELTS (non-native English)</li><li>December 1, 2026 5:00 PM PT deadline</li><li>Fall entry only; no deferral</li><li>May apply to Stanford GSB PhD and another Stanford program simultaneously</li></ul>",
        "research": "<ul><li>Empirical financial accounting and capital markets</li><li>Analytical/positive accounting theory</li><li>Managerial accounting and management control</li><li>Disclosure and corporate governance</li><li>Audit and regulation</li><li>Taxation and organizational economics</li><li>International accounting standards</li></ul>",
        "source": '<a href="https://www.gsb.stanford.edu/programs/phd" target="_blank">Stanford GSB PhD Program</a> | <a href="https://www.gsb.stanford.edu/programs/phd/admission/application-materials/graduate-record-examination-gre" target="_blank">GRE Requirements</a> | <a href="https://www.gsb.stanford.edu/programs/phd/admission/deadline-decisions" target="_blank">Deadline & Decisions</a>',
    },
    "nu-kellogg-acct-phd": {
        "school": "Kellogg School of Management, Northwestern",
        "en": "PhD in Accounting Information & Management",
        "deg": "Doctor of Philosophy (PhD)",
        "dur": "5 years full-time; empirical/archival and analytical/theoretical research methods; ~25 PhD students enter Kellogg across all programs each year; fall-only admission",
        "ddl": "Fall 2027: December 15, 2026. Fee $95 (or $175 dual application with Economics PhD). Decisions late February/early March. No online/part-time.",
        "lang": "TOEFL or IELTS required. Northwestern Graduate School minimum TOEFL iBT 90 (pre-Jan 21 2026) or 4.5 (post-Jan 21 2026). ETS code 1565, dept 01.",
        "test_cls": "GRE or GMAT required for Accounting Information & Management (both accepted). GRE code 1565; GMAT 6WZ-3J-54. No minimum; holistic review. Recommended: calculus, real analysis, linear algebra, optimization, probability, statistics. About half have graduate degree.",
        "tui": "5-year guaranteed financial aid: stipend + full tuition scholarship + annual health insurance. Moving allowance, computer subsidy, conference travel budget included.",
        "overview": "Kellogg's Accounting Information & Management doctoral program trains scholars in empirical/archival and analytical/theoretical research methods. Students receive rigorous training in economics and econometrics alongside specialized accounting and finance coursework. About half of entering students hold a graduate degree.",
        "requirements": "<ul><li>Bachelor's degree; master's not required (about half of entering students have one)</li><li>GRE or GMAT (both accepted)</li><li>TOEFL or IELTS (non-native English)</li><li>3+ letters of recommendation</li><li>Statement of purpose, resume, transcripts</li><li>$95 application fee ($175 dual with Economics PhD)</li><li>December 15, 2026 deadline</li><li>Fall entry only; no online/part-time</li><li>Recommended: calculus, real analysis, linear algebra, optimization, probability, statistics</li></ul>",
        "research": "<ul><li>Empirical archival research in capital markets</li><li>Analytical/theoretical models of disclosure</li><li>Role of information intermediaries in capital markets</li><li>Public and private pensions</li><li>Changing role of the audit function</li><li>Discretionary disclosures and accounting-based valuation</li><li>International accounting standards and regulation</li></ul>",
        "source": '<a href="http://www.kellogg.northwestern.edu/doctoral/programs/accounting.aspx" target="_blank">Kellogg PhD in Accounting Information & Management</a> | <a href="http://www.kellogg.northwestern.edu/admissions/phd-admissions/phd-how-to-apply/" target="_blank">How to Apply</a> | <a href="http://www.kellogg.northwestern.edu/doctoral/faqs/" target="_blank">PhD FAQ</a>',
    },
    "col-gsb-acct-phd": {
        "school": "Columbia Business School",
        "en": "PhD in Accounting",
        "deg": "Doctor of Philosophy (PhD)",
        "dur": "4-5 years full-time; one of five CBS PhD divisions; highly selective, fewer than 5% of applicants admitted; fall-only admission",
        "ddl": "Fall 2027: application opens September 1, 2026; deadline December 15, 2026. Fee $100. Fall entry only.",
        "lang": "TOEFL or IELTS required unless applicant holds a degree from an institution where English was the language of instruction.",
        "test_cls": "GRE or GMAT required (one of the two). No minimum score. 2 letters required (up to 4 accepted). Essay/personal statement required. Note: DRO PhD is GRE/GMAT-optional, but Accounting requires one.",
        "tui": "Fully funded by Columbia Business School: tuition + stipend + health insurance. PhD Admitted Students Day hosted for invited candidates.",
        "overview": "Columbia Business School's Accounting PhD is highly selective, admitting fewer than 5% of applicants in a typical year. The program emphasizes rigorous research and analytical skills, preparing students for academic careers in accounting.",
        "requirements": "<ul><li>Bachelor's degree; master's not required</li><li>GRE or GMAT required (one of the two)</li><li>TOEFL or IELTS (if applicable)</li><li>2 letters of recommendation (up to 4 accepted)</li><li>Essay/personal statement, transcripts</li><li>$100 application fee</li><li>December 15, 2026 deadline</li><li>Fall entry only</li></ul>",
        "research": "<ul><li>Empirical financial accounting and capital markets</li><li>Analytical/positive accounting theory</li><li>Managerial accounting and control systems</li><li>Disclosure, earnings quality, and governance</li><li>Audit and assurance</li><li>Taxation and firm behavior</li><li>International accounting and regulation</li></ul>",
        "source": '<a href="https://academics.business.columbia.edu/phd/accounting/admissions" target="_blank">CBS PhD Admissions in Accounting</a> | <a href="https://academics.business.columbia.edu/admissions/phd" target="_blank">PhD Admissions Overview</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"], 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)}")
