# -*- coding: utf-8 -*-
"""Round 225: batch add 5 Organizational Behavior / Management PhD programs
- stanford-gsb-ob-phd (Stanford GSB PhD Organizational Behavior)
- up-wharton-mgmt-phd (Wharton PhD Management)
- uchicago-booth-behav-phd (Chicago Booth PhD Behavioral Science)
- nu-kellogg-mo-phd (Northwestern Kellogg PhD Management & Organizations)
- col-gsb-mgmt-phd (Columbia GSB PhD Management)
Key finding: Stanford GSB OB is GRE-ONLY (does not accept GMAT); other 4 accept GRE or GMAT.
Deadlines: Dec 1 (Stanford GSB 5pm PT) vs Dec 15 (Wharton/Booth/Kellogg/Columbia).
All fully funded. Columbia Management acceptance rate <5%.
"""
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-ob-phd",
        "s": "stanford",
        "n": "组织行为学博士",
        "en": "PhD in Organizational Behavior (Stanford Graduate School of Business)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "5-6 years full-time; ~20 OB students in residence; interdisciplinary training with Psychology and Sociology departments; 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 ONLY (per Stanford GSB field table: Organizational Behavior = GRE only, GMAT not accepted). ETS code 4704. All GRE scores from Dec 1, 2021-Dec 1, 2026 must be reported (no superscore). No minimum score. Prerequisites (to be completed or obtained Year 1): one course each in calculus, linear algebra, probability, and mathematical statistics."},
        "tui": "Full fellowship: tuition + stipend + health insurance. Knight-Hennessy Scholars available. Research assistantships and teaching assistantships available.",
        "url": "details/stanford-gsb-ob-phd.html",
    },
    {
        "id": "up-wharton-mgmt-phd",
        "s": "up",
        "n": "管理学博士",
        "en": "PhD in Management (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; admitted TOEFL averages reported in FAQ.",
        "test": {"cls": "GRE or GMAT required (both accepted for Management). 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. ETS code for Wharton Doctoral Office."},
        "tui": "Full fellowship: tuition + living stipend + health insurance. All admitted Wharton doctoral students receive full funding.",
        "url": "details/up-wharton-mgmt-phd.html",
    },
    {
        "id": "uchicago-booth-behav-phd",
        "s": "uchicago",
        "n": "行为科学博士",
        "en": "PhD in Behavioral Science (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; joint PhD in Psychology & Business available (apply within first 2 years); 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. ETS code for Booth Stevens.",
        "test": {"cls": "GRE or GMAT required (both accepted for Behavioral Science). 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."},
        "tui": "Full funding: tuition + stipend + health insurance. Stevens Doctoral Program funds all admitted students.",
        "url": "details/uchicago-booth-behav-phd.html",
    },
    {
        "id": "nu-kellogg-mo-phd",
        "s": "nu",
        "n": "管理与组织学博士",
        "en": "PhD in Management & Organizations (Kellogg School of Management, Northwestern University)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "5 years full-time; 2 years coursework + written qualifying field exam(s) + original research papers + oral presentations; fall-only admission; no online/part-time option",
        "ddl": "Fall 2027: December 15, 2026. Decisions late February / early March. Fall entry only. Fee $95.",
        "lang": "TOEFL or IELTS required for non-native English speakers per Northwestern graduate admissions.",
        "test": {"cls": "GRE or GMAT required (both accepted for Management & Organizations). Note: Management & Organizations and Sociology track requires GRE only. ETS code 1565 (Northwestern Graduate School); GMAT code 6WZ-3J-54. No minimum score; holistic review. Writing sample optional. Strongly recommended: list six most rigorous math/economics courses for quantitative tracks."},
        "tui": "5-year guaranteed financial aid package: tuition + stipend + health insurance + moving allowance + computer equipment subsidy + conference travel budget.",
        "url": "details/nu-kellogg-mo-phd.html",
    },
    {
        "id": "col-gsb-mgmt-phd",
        "s": "col",
        "n": "管理学博士",
        "en": "PhD in Management (Columbia Business School)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 0,
        "dur": "4-5 years full-time; small cohort; fall-only admission; highly selective (<5% acceptance rate historically)",
        "ddl": "Fall 2027: application opens September 1, 2026; submission deadline December 15, 2026. Fall entry only.",
        "lang": "English equivalency exam required for non-native English speakers per Columbia graduate admissions.",
        "test": {"cls": "GRE or GMAT required (both accepted for Management; DRO division has GRE/GMAT OPTIONAL but Management division still requires). No minimum score. Note: Columbia GSB PhD code is 6442 (GRE). Scores valid 5 years. Transcripts, essay, 2 letters of recommendation, application fee required."},
        "tui": "Full funding: tuition + stipend + health insurance. All admitted CBS PhD students receive full financial support.",
        "url": "details/col-gsb-mgmt-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 organizational behavior / management. 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 = {
    "stanford-gsb-ob-phd": {
        "school": "Stanford Graduate School of Business",
        "en": "PhD in Organizational Behavior",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "No (social/behavioral science)",
        "dur": "5-6 years full-time; ~20 OB students in residence; interdisciplinary with Psychology and Sociology",
        "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 ONLY (GMAT not accepted for OB). ETS 4704. All GRE scores from Dec 1, 2021-Dec 1, 2026 must be reported (no superscore). Prereqs: calculus, linear algebra, probability, mathematical statistics.",
        "tui": "Full fellowship: tuition + stipend + health insurance. Knight-Hennessy Scholars available.",
        "overview": "Stanford GSB Organizational Behavior PhD studies behavior of individuals, groups, and organizations from psychological and sociological perspectives. The program provides broad interdisciplinary training with Stanford's Psychology and Sociology departments. Two subareas: Macro OB and Micro OB. A small number of students are accepted each year, with about 20 OB students in residence total.",
        "requirements": "<ul><li>Bachelor's degree; strong preparation in social sciences (psychology, sociology, economics) preferred</li><li>GRE required (GMAT NOT accepted for OB field)</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>Math prereqs (calculus, linear algebra, probability, math statistics) to be completed or obtained Year 1</li></ul>",
        "research": "<ul><li>Micro OB: judgment and decision-making, motivation, self-regulation, emotion, leadership</li><li>Macro OB: organizational structure, culture, networks, social movements, institutions</li><li>Interdisciplinary ties with Psychology and Sociology departments</li><li>Cross-registration and colloquia available</li><li>Weekly lab meetings and brown-bag seminars</li></ul>",
        "source": '<a href="https://www.gsb.stanford.edu/programs/phd/fields/organizational-behavior" target="_blank">Stanford GSB PhD Organizational Behavior</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-mgmt-phd": {
        "school": "The Wharton School, UPenn",
        "en": "PhD in Management",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "No (social/behavioral science)",
        "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 Doctoral Programs offers 9 PhD fields including Management. The Management division trains scholars in organizational behavior, strategy, international management, and operations/information management. Full-time study only, beginning in the fall semester each year. Completion typically takes 4-5 years.",
        "requirements": "<ul><li>Bachelor's degree</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>Many Management subfields require a preliminary research paper</li></ul>",
        "research": "<ul><li>Organizational behavior and theory</li><li>Strategic management and technological innovation</li><li>International management</li><li>Operations and information management</li><li>Human resources and labor economics</li><li>Entrepreneurship</li><li>Public and non-profit management</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-behav-phd": {
        "school": "Chicago Booth School of Business",
        "en": "PhD in Behavioral Science",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "No (social/behavioral science)",
        "dur": "4-5 years full-time; coursework/exams Year 1-2; dissertation Year 3; joint Psychology & Business available",
        "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 or GMAT required (both 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.",
        "tui": "Full funding: tuition + stipend + health insurance. Stevens Doctoral Program funds all admitted students.",
        "overview": "Chicago Booth Behavioral Science PhD explores how people make decisions and interact, drawing on cognitive and social psychology, economics, and related fields. Research contexts include negotiation, power and influence, motivation and self-control. Students can augment studies with economics, policy and intervention, psychology, marketing, finance, sociology, and public policy. A joint PhD in Psychology and Business is available (apply within first 2 years).",
        "requirements": "<ul><li>Bachelor's degree; strong social/behavioral science background preferred</li><li>GRE or GMAT required (no waivers)</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>Optional: joint PhD in Psychology & Business (apply within first 2 years)</li></ul>",
        "research": "<ul><li>Judgment and decision-making</li><li>Motivation and self-regulation</li><li>Social influence, negotiation, power</li><li>Behavioral economics and policy intervention</li><li>Psychology of groups and organizations</li><li>Well-being and behavioral health</li></ul>",
        "source": '<a href="https://www.chicagobooth.edu/phd/dissertation-areas/behavioral-science" target="_blank">Chicago Booth PhD Behavioral Science</a> | <a href="https://www.chicagobooth.edu/phd/faq" target="_blank">PhD FAQ (test requirements)</a> | <a href="https://www.chicagobooth.edu/phd/admissions" target="_blank">Admissions (2026-27 class profile)</a>',
    },
    "nu-kellogg-mo-phd": {
        "school": "Northwestern University Kellogg School of Management",
        "en": "PhD in Management & Organizations",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "No (social/behavioral science)",
        "dur": "5 years full-time; 2 years coursework + field exam(s) + research papers + oral presentations; no online/part-time",
        "ddl": "Fall 2027: December 15, 2026. Decisions late February / early March. Fall only. Fee $95.",
        "lang": "TOEFL or IELTS required per Northwestern graduate admissions.",
        "test_cls": "GRE or GMAT required (both accepted for M&O). Note: M&O & Sociology track requires GRE only. ETS 1565; GMAT 6WZ-3J-54. No minimum score; holistic. Writing sample optional. Recommended: list six most rigorous math/economics courses.",
        "tui": "5-year guaranteed aid: tuition + stipend + health insurance + moving allowance + computer subsidy + conference travel budget.",
        "overview": "Kellogg PhD in Management & Organizations trains scholars for academic careers in organizational behavior, psychology, and sociology. The program is well suited for students with social science backgrounds (economics, political science, psychology, sociology) as well as math, natural sciences, or engineering. Annual average class size is ~20 students across all PhD fields. Kellogg also offers a joint PhD in Management & Organizations and Sociology.",
        "requirements": "<ul><li>Bachelor's degree before enrollment</li><li>GRE or GMAT required (M&O accepts both; M&O&Sociology requires GRE only)</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</li><li>December 15, 2026 deadline</li><li>Fall entry only; no online/part-time</li><li>Strong quantitative/verbal skills; writing sample optional</li></ul>",
        "research": "<ul><li>Organizational behavior and theory</li><li>Social psychology in organizations</li><li>Economic sociology and organizational sociology</li><li>Groups, teams, and leadership</li><li> Diversity, culture, and institutions</li><li>Joint PhD in M&O and Sociology available</li></ul>",
        "source": '<a href="http://www.kellogg.northwestern.edu/admissions/phd-admissions/phd-how-to-apply/" target="_blank">Kellogg PhD How to Apply</a> | <a href="http://www.kellogg.northwestern.edu/doctoral/faqs/" target="_blank">Kellogg PhD FAQ</a> | <a href="https://www.kellogg.northwestern.edu/-/media/files/doctoral/2017/kellogg-phd-brochure.pdf" target="_blank">PhD Brochure (funding package)</a>',
    },
    "col-gsb-mgmt-phd": {
        "school": "Columbia Business School",
        "en": "PhD in Management",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "No (social/behavioral science)",
        "dur": "4-5 years full-time; small cohort; highly selective (<5% acceptance historically); fall-only admission",
        "ddl": "Fall 2027: opens September 1, 2026; deadline December 15, 2026. Fall only.",
        "lang": "English equivalency exam required per Columbia graduate admissions.",
        "test_cls": "GRE or GMAT required (Management division; DRO division has GRE/GMAT OPTIONAL but Management still requires). No minimum score. ETS code 6442 (GRE). Scores valid 5 years. Transcripts, essay, 2 letters of recommendation, application fee required.",
        "tui": "Full funding: tuition + stipend + health insurance. All admitted CBS PhD students receive full financial support.",
        "overview": "Columbia Business School offers PhD programs through five academic divisions: Accounting, Decision Risk & Operations (DRO), Finance, Management, and Marketing. The Management division trains scholars in organizational behavior, leadership, and human capital. The program is highly competitive; fewer than 5% of applicants are admitted in a typical year.",
        "requirements": "<ul><li>Bachelor's degree</li><li>GRE or GMAT required (Management division; no minimum score)</li><li>English equivalency exam (non-native English)</li><li>Application form, essay(s)</li><li>2 letters of recommendation</li><li>Transcripts from all post-secondary institutions</li><li>Application fee</li><li>December 15, 2026 deadline (opens September 1, 2026)</li><li>Fall entry only</li><li>Note: DRO division has GRE/GMAT optional; Management division still requires scores</li></ul>",
        "research": "<ul><li>Organizational behavior and theory</li><li>Leadership and human capital</li><li>Social networks and organizational sociology</li><li>Negotiation and decision processes</li><li>Behavioral and experimental research</li><li>Cross-disciplinary ties with Columbia Psychology, Sociology, SIPA</li></ul>",
        "source": '<a href="https://academics.business.columbia.edu/phd/management/admissions" target="_blank">CBS PhD Management Admissions</a> | <a href="https://academics.business.columbia.edu/admissions/phd/application-requirements" target="_blank">PhD Application Requirements</a> | <a href="https://academics.business.columbia.edu/admissions/phd" target="_blank">PhD Overview (5 divisions)</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)}")
