# -*- coding: utf-8 -*-
# r270: Batch add 5 more Neuroscience PhD entries (fifth wave)
# 1. WashU Neurosciences PhD (DBBS track)
# 2. Notre Dame Neuroscience PhD (IBMS cluster)
# 3. UVA Neuroscience PhD (BIMS track)
# 4. UNC Neuroscience PhD (BBSP track)
# 5. Dartmouth Integrative Neuroscience PhD (IND)
import os, re, json

ROOT = r"D:\work buddy\2026-11-05-14-15-52"
INDEX = os.path.join(ROOT, "index_main.html")

DETAIL_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{title}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',sans-serif;max-width:980px;margin:24px auto;padding:0 20px;color:#222;line-height:1.65}}
h1{{font-size:24px;border-bottom:3px solid #1a4480;padding-bottom:8px}}
h2{{font-size:18px;color:#1a4480;margin-top:28px;border-left:4px solid #1a4480;padding-left:10px}}
.card{{background:#f7f9fc;border:1px solid #d8e1ee;border-radius:8px;padding:14px 18px;margin:10px 0}}
.label{{color:#666;font-size:13px}}
.val{{font-weight:600;color:#111}}
a{{color:#1a4480}}
.tag{{display:inline-block;background:#e8f0fb;color:#1a4480;border-radius:4px;padding:2px 8px;font-size:12px;margin-right:6px}}
</style>
</head>
<body>
<h1>{title}</h1>
<div class="card">
<div class="label">School</div><div class="val">{school}</div>
<div class="label">Program</div><div class="val">{en}</div>
<div class="label">Degree</div><div class="val">{deg}</div>
<div class="label">STEM</div><div class="val">{stem_label}</div>
</div>
<h2>1. Degree & Curriculum</h2>
<div class="card">{curriculum}</div>
<h2>2. Application Deadline</h2>
<div class="card">{ddl}</div>
<h2>3. Language Requirement</h2>
<div class="card">{lang}</div>
<h2>4. Standardized Tests</h2>
<div class="card">{test}</div>
<h2>5. Tuition & Funding</h2>
<div class="card">{tui}</div>
<h2>6. Source</h2>
<div class="card">{src}</div>
<p><a href="index_main.html">&larr; Back to Program Index</a></p>
</body>
</html>
"""

PAGES = [
    {
        "id": "wustl-neurosciences-phd",
        "s": "wustl",
        "n": "圣路易斯华盛顿大学神经科学博士",
        "en": "Neurosciences PhD (DBBS)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "7 years",
        "ddl": "November 15, 11:59 PM EST (application opens September 1; no rolling admissions)",
        "lang": "TOEFL / IELTS accepted for international applicants; WashU Graduate School standard English proficiency requirement applies. ETS institution 6929.",
        "test": {"cls": "GRE NOT REQUIRED NOR ACCEPTED per WashU DBBS unified admissions policy (dbbs.wustl.edu/admissions). All DBBS PhD programs share this policy; no GRE field in application."},
        "tui": "Full tuition and yearly stipend guaranteed to all accepted students (no separate application for funding). Application fee $45 USD (fee waivers available in certain circumstances). Students may work with any of 700+ DBBS faculty across 15+ departments including Neuroscience, Anesthesiology, Biochemistry & Molecular Biophysics, Biology, Biomedical Engineering, Cell Biology & Physiology, Developmental Biology, Genetics, Molecular Microbiology, Neurology, Neurosurgery, Ophthalmology & Visual Sciences, Pathology & Immunology, Physics, Psychiatry, Psychological & Brain Sciences, and Radiology. Qualifying examination + Research Advisory Committee (RAC) + dissertation defense required. Note: separate from Psychological & Brain Sciences PhD (Arts & Sciences, different application).",
        "url": "details/wustl-neurosciences-phd.html",
        "title": "Washington University in St. Louis Neurosciences PhD",
        "school": "Washington University School of Medicine (Roy and Diana Vagelos Division of Biology & Biomedical Sciences - DBBS)",
        "curriculum": ("Neurosciences is one of 12 PhD programs within the DBBS umbrella at WashU. "
                       "DBBS offers a student-driven course of study that is a flexible, personalized learning pathway. "
                       "Students perform laboratory rotations during Year 1 and declare a thesis advisor by the end of Year 1. "
                       "Program degree length is 7 years (per WashU Bulletin 2026-27). "
                       "Faculty from a variety of departments serve as advisors for thesis research and as teaching faculty. "
                       "Historic strengths include nerve conduction velocity (Erlanger) and discovery of nerve growth factor (Levi-Montalcini, Cohen, Hamburger). "
                       "To earn PhD: complete all required courses, maintain satisfactory academic progress, pass qualifying examination, complete doctoral candidacy requirements, create Research Advisory Committee (RAC), submit Title/Scope/Procedure Form, fulfill residence and Mentored Experience Requirements, write defend and submit dissertation."),
        "src": "https://dbbs.wustl.edu/admissions/ ; https://dbbs.wustl.edu/programs/neurosciences/ ; https://bulletin.wustl.edu/medicine/degrees-offerings/dbbs-neurosciences-phd/dbbs-neurosciences-phd_degreerequirements.pdf"
    },
    {
        "id": "notre-neuroscience-phd",
        "s": "notre",
        "n": "圣母大学神经科学博士",
        "en": "Neuroscience PhD (Integrated Biomedical Sciences - IBMS cluster)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years",
        "ddl": "December 1 (Fall entry)",
        "lang": "TOEFL / IELTS / Duolingo English Test required for non-native speakers of English. ETS institution 1839 (University of Notre Dame).",
        "test": {"cls": "GRE General Test optional per Notre Dame Graduate School degree program listing (IBMS = GRE Optional). GRE Subject not required. Note: Notre Dame Psychology PhD (separate department) still requires GRE General."},
        "tui": "Full tuition stipend and health insurance guaranteed (IBMS standard package). 2 years minimum residency required. Year 1 includes three research rotations; students matriculate into a department upon choosing their research advisor. 8 interdisciplinary clusters available: Biophysics & Structural Biology, Genomics & Proteomics, Cancer Biology, Immunology & Infectious Diseases, Chemical Biology & Molecular Pharmacology, Computational Biology & Bioinformatics, Cellular & Molecular Biology, and Neuroscience. Contact: Jeff Schorey, Director of Graduate Studies, ibms@nd.edu. Note: separate from Psychology PhD which requires GRE General.",
        "url": "details/notre-neuroscience-phd.html",
        "title": "University of Notre Dame Neuroscience PhD",
        "school": "University of Notre Dame Graduate School (Integrated Biomedical Sciences - IBMS)",
        "curriculum": ("Neuroscience is one of eight interdisciplinary clusters within the Integrated Biomedical Sciences (IBMS) PhD program at Notre Dame. "
                       "IBMS offers cross-departmental research and training in biomedical sciences. "
                       "Each cluster involves faculty from multiple departments. "
                       "First-year students perform three research rotations over the course of the academic year, and matriculate into a department upon choosing their research advisor. "
                       "Minimum 2 years residency required by the Graduate School. "
                       "Application materials: CV, statement of intent, three letters of recommendation, summary of research experience, unofficial transcripts. "
                       "Updated: 9/28/2026."),
        "src": "https://graduateschool.nd.edu/degree-programs/integrated-biomedical-sciences-phd---doctoral/ ; https://ibms.nd.edu/ ; https://graduateschool.nd.edu/admissions/faq/"
    },
    {
        "id": "uva-neuroscience-phd",
        "s": "uva",
        "n": "弗吉尼亚大学神经科学博士",
        "en": "Neuroscience Graduate Program PhD (BIMS)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years",
        "ddl": "November 15, 11:59 PM (application opens September 1; no spring admissions; Summer/Fall entry only)",
        "lang": "TOEFL iBT minimum 90 overall with sectional minimums of 22 speaking / 22 writing / 23 reading / 23 listening; TOEFL paper-based minimum 600; IELTS minimum 7.0 in each section. Waived for applicants with baccalaureate or master's degree from institution where English is primary language of instruction. ETS institution 5820.",
        "test": {"cls": "GRE not required. UVA BIMS umbrella program does not require GRE; UVA Psychology PhD (separate department) explicitly states: 'THE UVA PSYCHOLOGY PHD PROGRAM DOES NOT REQUIRE THE GENERAL GRE OR THE SUBJECT GRE. WE WILL NOT BE COLLECTING ANY INFORMATION RELATED TO GRE EXAM SCORES ON THE APPLICATION. PLEASE DO NOT SUBMIT GRE SCORES TO UVA FOR OUR PROGRAM.'"},
        "tui": "Full tuition stipend and health insurance guaranteed (BIMS standard package). Application fee $85 non-refundable (fee waivers available). Over 70 faculty from 17+ departments including School of Medicine basic science departments (Biochemistry & Molecular Genetics, Cell Biology, Microbiology, Neuroscience, Pharmacology), clinical departments (Anesthesiology, Neurology), and College of Arts & Sciences (Biology, Chemistry, Psychology). Two short personal statements required (describing prior experience, passion for research, motivation for graduate school, and interest in UVA BIMS). Three letters of recommendation. Note: separate from Psychology PhD (Systems & Behavioral Neuroscience track) which is a different application.",
        "url": "details/uva-neuroscience-phd.html",
        "title": "University of Virginia Neuroscience Graduate Program PhD",
        "school": "University of Virginia School of Medicine (Biomedical Sciences Graduate Program - BIMS)",
        "curriculum": ("The Neuroscience Graduate Program (NGP) is part of the Biomedical Sciences Graduate Program (BIMS) umbrella at UVA School of Medicine. "
                       "Applicants must apply through BIMS; NGP then reviews applications. "
                       "NGP coalesces over 70 faculty from more than 17 departments into a unified program leading to the PhD degree in Neuroscience. "
                       "A unique feature is the active role students play in the workings of the program, with student representation on committees for recruiting, education, seminars, and selection of the program director. "
                       "Students are involved in active research programs, journals clubs, outreach (Brain Awareness Week), and seminars. "
                       "No spring admissions. Fall only."),
        "src": "https://neurograd.virginia.edu/prospective-students ; https://neurograd.virginia.edu/ngp-application-faq ; https://records.ureg.virginia.edu/content.php?catoid=73&navoid=6768 ; https://psychology.as.virginia.edu/graduate-studies"
    },
    {
        "id": "unc-neuroscience-phd",
        "s": "unc",
        "n": "北卡教堂山大学神经科学博士",
        "en": "Neuroscience Curriculum PhD (BBSP)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5.3 years (average time to graduation)",
        "ddl": "Early December (apply via BBSP; BBSP deadline typically in November - check bbsp.unc.edu for exact date; Fall entry only)",
        "lang": "TOEFL / IELTS / Duolingo English Test required for international applicants (no more than two years old). UNC Graduate School standard English proficiency requirement applies. ETS institution 5816.",
        "test": {"cls": "GRE not required. Effective 2020, UNC Psychology & Neuroscience Department does not review or require GRE scores from applicants. BBSP umbrella program also does not require GRE."},
        "tui": "Full tuition and stipend guaranteed (BBSP standard package). Three letters of recommendation required. Statement of purpose (four short essay questions, each 250 words or less) + Resume/CV. Non-refundable application fee (fee waivers available). Over 80 faculty in 12 departments and 5 specialized research centers participate in the interdisciplinary program. Typically 8-12 students accepted each year depending on available funding. Average of 45 students at different levels of training at any given time. Collaborative with Duke University, NC State University, National Institute of Environmental Health Science (NIEHS), and North Carolina Central University. Note: separate from Psychology & Neuroscience Department PhD (different application).",
        "url": "details/unc-neuroscience-phd.html",
        "title": "UNC Chapel Hill Neuroscience Curriculum PhD",
        "school": "University of North Carolina at Chapel Hill (Biological and Biomedical Sciences Program - BBSP)",
        "curriculum": ("The Neuroscience Curriculum (NBIO) at UNC-Chapel Hill is a broadly based interdisciplinary graduate training program in the neurosciences. "
                       "Neuroscience by its very nature is an interdisciplinary endeavor; the curriculum provides a broadly structured training curriculum and research environment spanning from genetic studies of the nervous system through the complexities of human cognitive function. "
                       "Applicants are urged to complete their applications through BBSP around BBSP's deadline (typically November). "
                       "The Curriculum facilitates communication between neuroscientists across departmental barriers. "
                       "Program strengths: PhD training that incorporates a broad interdisciplinary background; opportunities for thesis work in laboratories representing the full spectrum of modern neuroscience; promotion of the very latest technical approaches; facilitation of collaborative, interdisciplinary and translational research. "
                       "NBIO strongly supports and fosters communication among neuroscientists at UNC and neighboring institutions."),
        "src": "https://catalog.unc.edu/graduate/schools-departments/neuroscience/ ; https://catalog.unc.edu/graduate/schools-departments/neuroscience/neuroscience.pdf ; https://bbsp.unc.edu/admissions/"
    },
    {
        "id": "dartmouth-integrative-neuroscience-phd",
        "s": "dartmouth",
        "n": "达特茅斯学院整合神经科学博士",
        "en": "Integrative Neuroscience PhD (IND)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years",
        "ddl": "December 1, 2026 (Priority Deadline: November 20, 2026; applications received by November 20 will have priority consideration; Fall entry only)",
        "lang": "TOEFL / IELTS / Duolingo English Test required for non-US citizens unless earning/earned a degree from US or Canada institution or primary language of instruction at non-US institution was English. ETS code 3351 (Guarini School).",
        "test": {"cls": "GRE Optional per Guarini School of Graduate and Advanced Studies program listing. Note: separate from Dartmouth Psychological & Brain Sciences (PBS) PhD where PBS department page states GRE scores required for 2026-27 cycle, but Guarini School unified page lists PBS as GRE Optional - discrepancy should be verified on current PBS admissions page before applying."},
        "tui": "Full tuition and stipend guaranteed (Guarini standard package). Application fee $75 (per current Guarini School page; older page listed $150 which is outdated). 3 letters of recommendation (up to 4 accepted). 2 required essay prompts (personal statement). Unofficial transcripts uploaded during application; official transcripts required only if offer of admission is made. Virtual interviews on January 7-8, 2027 via Gathertown virtual Dartmouth campus. On-campus invitation March 4-5, 2027. Post-interview decisions by January 31, 2027. Note: separate from Psychological & Brain Sciences PhD (PBS department, different application).",
        "url": "details/dartmouth-integrative-neuroscience-phd.html",
        "title": "Dartmouth College Integrative Neuroscience PhD",
        "school": "Geisel School of Medicine at Dartmouth (Guarini School of Graduate and Advanced Studies)",
        "curriculum": ("Integrative Neuroscience at Dartmouth (IND) is a PhD program. "
                       "Admission is granted by the Guarini School of Graduate and Advanced Studies at Dartmouth upon recommendation of the IND Admissions Committee. "
                       "Applications accepted from beginning of September through December 1st. "
                       "Program supplement includes Neuropathology. "
                       "Successful applicants begin their studies in the fall of the following year. "
                       "Interview weekend is a critical part of the application process: virtual Gathertown interviews January 7-8, 2027, on-campus invitation March 4-5, 2027. "
                       "IND will notify candidates of post-interview decision by email or postal mail by January 31st. "
                       "Dartmouth also offers separate PhD programs in Cognitive Neuroscience (within PBS department), Molecular and Cellular Biology, Quantitative Biomedical Sciences, and Psychological & Brain Sciences."),
        "src": "https://graduate.dartmouth.edu/admissions/programs/integrative-neuroscience?p=6329 ; https://sites.dartmouth.edu/ind/apply/ ; https://graduate.dartmouth.edu/admissions/applying-dartmouth ; https://graduate.dartmouth.edu/academics/programs/integrative-neuroscience"
    }
]


def main():
    with open(INDEX, "r", encoding="utf-8") as f:
        html = f.read()

    # Build detail pages
    for p in PAGES:
        stem_label = "Yes (STEM-designated)" if p["stem"] == 1 else "No"
        out = DETAIL_TEMPLATE.format(
            title=p["title"], school=p["school"], en=p["en"], deg=p["deg"],
            stem_label=stem_label, curriculum=p["curriculum"], ddl=p["ddl"],
            lang=p["lang"], test=p["test"]["cls"], tui=p["tui"], src=p["src"]
        )
        path = os.path.join(ROOT, p["url"])
        with open(path, "w", encoding="utf-8") as f:
            f.write(out)
        print("Wrote:", p["url"])

    # Build PROGRAMS block
    prog_lines = []
    for p in PAGES:
        prog_lines.append(
            '{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test}"}},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=p["test"]["cls"], tui=p["tui"], url=p["url"]
            )
        )
    new_prog_block = "," + ",".join(prog_lines)

    # Locate PROGRAMS array end via bracket-depth matching
    m = re.search(r"const\s+PROGRAMS\s*=\s*\[", html)
    if not m:
        raise SystemExit("PROGRAMS array not found")
    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
    # i is just past the closing ]; insert before the ]
    insert_at = i - 1
    new_html = html[:insert_at] + new_prog_block + html[insert_at:]

    # Build VD block
    vd_entries = [p["url"] for p in PAGES]
    vd_block = "," + ",".join('"{}"'.format(u) for u in vd_entries)

    # Locate VERIFIED_DETAILS Set end via parenthesis-depth matching on new_html
    m2 = re.search(r"const\s+VERIFIED_DETAILS\s*=\s*new\s+Set\s*\(\s*\[", new_html)
    if not m2:
        raise SystemExit("VERIFIED_DETAILS Set not found")
    start2 = m2.end()
    depth = 1
    j = start2
    while j < len(new_html) and depth > 0:
        c = new_html[j]
        if c == "[":
            depth += 1
        elif c == "]":
            depth -= 1
        j += 1
    # j is just past the closing ]; insert before the ]
    insert_at2 = j - 1
    new_html = new_html[:insert_at2] + vd_block + new_html[insert_at2:]

    with open(INDEX, "w", encoding="utf-8") as f:
        f.write(new_html)
    print("Appended {} PROGRAMS entries and {} VD entries".format(len(PAGES), len(PAGES)))
    print("Done. File size:", os.path.getsize(INDEX))


if __name__ == "__main__":
    main()
