# -*- coding: utf-8 -*-
"""Round 238: batch add 5 more Biology PhD (Dartmouth MCB / UBC Zoology / McGill Biology / UofT EEB / Waterloo Biology).
Key finding: All five are GRE-free / not required. Deadlines:
- Dartmouth MCB: Dec 1 (Priority Nov 15)
- UBC Zoology PhD: International Jan 4, 2027 (later than US Dec 1; Canadian cycle)
- McGill Biology PhD: International Jan 15 (Fall), Domestic Feb 15
- UofT EEB PhD: International ~Dec 9, Domestic ~Jan 9
- Waterloo Biology PhD: rolling, supervisor-linked
Must contact supervisor before applying at UBC/McGill/UofT/Waterloo (Canadian model).
"""
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": "dartmouth-mcb-phd",
        "s": "dartmouth",
        "n": "分子与细胞生物学博士",
        "en": "PhD in Molecular and Cellular Biology (Dartmouth College Guarini School of Graduate and Advanced Studies; MCB Graduate Program; 4 home departments: Biological Sciences / Biochemistry & Cell Biology / Cancer Biology / Microbiology & Immunology)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "5-6 years full-time residential; fall-only admission; 3 research rotations; 1 term of teaching; qualifying exam (15-min private seminar + dissertation proposal defense); written thesis + oral defense; terminal MD/PhD track available",
        "ddl": "Fall 2027: **Priority Deadline November 15, 2026; Final Deadline December 1, 2026**. Applications submitted after Nov 15 still reviewed but no priority funding consideration; interview weekend late January; offers by late February; April 15 CGS reply.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English; ETS Dartmouth code 2519; English-medium undergraduate exempts. Guarini School minimum TOEFL iBT 80 (sectional minimums 22 reading, 22 listening, 7 speaking, 23 writing); IELTS Academic 7.0.",
        "test": {"cls": "GRE NOT LISTED AS REQUIRED (Dartmouth Guarini: GRE required by specific program; MCB Graduate Program does not list GRE as required in current cycle. Subject tests not required. 3 LOR; Statement of Purpose; CV; transcripts; bachelor's with strong biology/chemistry/math background)."},
        "tui": "Full funding for admitted PhD students through Dartmouth Guarini School (tuition + stipend + health insurance) via research/teaching assistantships and Guarini fellowships; guaranteed support for 5 years contingent on good standing.",
        "url": "details/dartmouth-mcb-phd.html",
    },
    {
        "id": "ubc-zoology-phd",
        "s": "ubc",
        "n": "动物学博士",
        "en": "PhD in Zoology (University of British Columbia, Faculty of Science, Department of Zoology; research in animal behavior, ecology, evolution, physiology, developmental biology, marine biology; closely linked to Botany PhD)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4-5 years full-time residential; fall primary (September 2027) with January/May intakes also available; **supervisor must be identified and agree to accept before application**; supervisory committee of 3 faculty; thesis proposal + oral defense",
        "ddl": "Fall 2027 (September): Application opens September 1, 2026. **International Applicant Deadline January 4, 2027; Canadian Applicant Deadline January 4, 2027**. Transcript deadline January 4, 2027; Referee deadline January 10, 2027. January 2028 intake: application opens January 1, 2027, deadline July 15, 2027.",
        "lang": "TOEFL iBT overall 90 (pre-1/21/26; sectional 22/22/22/22) or 4.5 (post-1/21/26; sectional 4.5/4.5/4.0/5.0); IELTS Academic overall 6.5 (sectional minimums 6.0); Duolingo DET 125 (sectional 115/120/120/115); English-medium degree exempts.",
        "test": {"cls": "GRE NOT REQUIRED (UBC Zoology PhD: 'The GRE is not required.' Subject tests not required. 2 LOR (ideally faculty who have directly supervised your research); CV; scanned/unofficial transcripts; bachelor's with strong biology background; minimum B+ average in last 2 years)."},
        "tui": "UBC-funded graduate support through departmental RA/TA and fellowships (minimum stipend package set by Faculty of Graduate and Postdoctoral Studies; international tuition differential waived through teaching/research assistantships). Application fee ~$150 CAD.",
        "url": "details/ubc-zoology-phd.html",
    },
    {
        "id": "mcg-biology-phd",
        "s": "mcg",
        "n": "生物学博士",
        "en": "PhD in Biology (McGill University Faculty of Science, Department of Biology; research in molecular/cellular/developmental biology, conservation/ecology/evolution, neurobiology and behavior; optional Neotropical Environment option with field work in Panama)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4-5 years full-time residential; **supervisor must be confirmed before application**; 2 LOR (must be academic, non-supervisor; institutional email only - no gmail/yahoo); McGill Harmonized Funding Policy guarantees minimum stipend; PhD1 (direct from BSc, CGPA 3.5+) or PhD2 (MSc entry)",
        "ddl": "Fall 2027 (September): Applications open September 15. **International Applicant Deadline January 15, 2027; Canadian/Permanent Resident Deadline February 15, 2027**. Winter 2028 (January): applications open February 15, international deadline August 1, domestic November 1. **Summer admission NOT offered**.",
        "lang": "TOEFL iBT minimum 86 (each component no less than 20) or IELTS Academic overall 6.5; ETS McGill code 0935; English-medium undergraduate / Canadian institution exempts; scores within 2 years.",
        "test": {"cls": "GRE NOT REQUIRED (McGill Biology: 'GRE General Test not required.' Subject tests not required. 2 LOR (institutional email required - gmail/yahoo/hotmail not accepted); CV; Personal Statement; transcripts; minimum CGPA 3.0/4.0 (or 3.2 in last 2 full-time years); direct BSc entry to PhD1 requires CGPA 3.5/4.0)."},
        "tui": "McGill Harmonized Funding Policy: guaranteed minimum stipend package for Biology PhD students (stipend + tuition offset) for 4 years; support through supervisor research grants, departmental RA/TA, and McGill Fellowships (e.g., Quebec Excellence, NSERC). Application fee ~$126 CAD.",
        "url": "details/mcg-biology-phd.html",
    },
    {
        "id": "ut-eeb-phd",
        "s": "ut",
        "n": "生态与进化生物学博士",
        "en": "PhD in Ecology and Evolutionary Biology (University of Toronto Faculty of Arts & Science, Department of Ecology & Evolutionary Biology; supervisory faculty across St. George, Mississauga, Scarborough campuses and Royal Ontario Museum)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4 years (5 years for direct entry from BSc); **supervisor must agree to accept and fund before application**; 2 FCE graduate courses (1.5 FCE for MSc-entry); mid-program Appraisal Examination; 2 research seminars; thesis defense; supervisors across all 3 campuses + Royal Ontario Museum",
        "ddl": "Fall 2027 (September): SGS portal opens November 6, 2026. **International Applicant Deadline ~December 9, 2026; Domestic Applicant Deadline ~January 9, 2027** (slightly later than typical Dec 1 US deadline; rolling review after deadline until positions filled). January/May entry possible under special circumstances.",
        "lang": "TOEFL iBT minimum 93 (sectional minimums 22/22/22/22) or IELTS Academic overall 7.0; MELAB / COPE also accepted; English-medium undergraduate exempts; scores within 2 years; ETS UofT code 0982.",
        "test": {"cls": "GRE NOT REQUIRED (UofT EEB: 'GRE scores are not required.' Subject tests not required. 3 LOR; SOP / Statement of Research Interests; CV; transcripts; minimum B+ average in final year of bachelor's and A- average in MSc (if applicable); direct BSc entry requires A- in EEB courses + strong research potential)."},
        "tui": "UofT Science-funded stipend: base stipend $18,000/year + tuition + fees (including UHIP for international) guaranteed for 'funded cohort'; departments may increase but cannot offer less than this minimum; RA/TA/department fellowships layered on top. Note: UofT EEB does NOT currently accept MSc applications from international students, but **PhD applications from international students ARE accepted**.",
        "url": "details/ut-eeb-phd.html",
    },
    {
        "id": "uw-biology-phd",
        "s": "uw",
        "n": "生物学博士（含 Water 方向）",
        "en": "PhD in Biology (University of Waterloo Faculty of Science, Department of Biology; research-based thesis; optional Collaborative Water Program specialization coordinated by the Water Institute across 11 academic units)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "4 years (48 months) full-time residential; **strongly advise establishing contact with potential supervisor before applying**; MSc transfer to PhD possible case-by-case; thesis-based research; 2 interdisciplinary water courses in Water specialization",
        "ddl": "Rolling admission for Fall (September), Winter (January), Spring (May) terms. International applicants advised to apply at least 6-8 months before intended start; domestic applicants 3-4 months. Recommended target: **February 1 for Fall September entry** (competitive funding consideration); applications reviewed on a continuous basis until supervisor-funded positions filled.",
        "lang": "TOEFL iBT minimum 90 (writing 25, speaking 25, reading/listening 22) or IELTS Academic overall 7.0 (writing 6.5, speaking 6.5); Duolingo DET also accepted; English-medium undergraduate exempts; scores within 2 years; ETS Waterloo code 0996.",
        "test": {"cls": "GRE NOT REQUIRED (Waterloo Biology Department does not require GRE for PhD admission. Subject tests not required. 3 LOR; CV; Statement of Research Interests; transcripts; minimum 75% overall standing in relevant MSc; direct BSc entry requires superior academic record and strong research experience; undergraduate degree in biology or related science)."},
        "tui": "Waterloo-funded graduate support through supervisor research grants, teaching assistantships, and Waterloo Graduate Scholarships (minimum stipend package; international differential tuition). Research-focused MSc/PhD track. Application fee ~$125 CAD.",
        "url": "details/uw-biology-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 in biological sciences at a top U.S. university (Dartmouth) or one of the three Canadian target universities (UBC / McGill / UofT / Waterloo). Admitted PhD students receive full financial support (tuition + stipend + insurance). Admission statistics shown are distribution ranges, not minimum thresholds. Course/credit details pending department bulletin verification. All five programs are STEM-designated per NSF GRFP / CIP codes. Canadian model: supervisor must be confirmed before application at UBC/McGill/UofT/Waterloo.
</div>
</body>
</html>
"""

PAGES = {
    "dartmouth-mcb-phd": {
        "school": "Dartmouth College Guarini School of Graduate and Advanced Studies - MCB Graduate Program",
        "en": "PhD in Molecular and Cellular Biology (MCB)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Life Sciences / CIP 26.xx)",
        "dur": "5-6 years full-time residential; fall-only; 3 research rotations; 1 term teaching; qualifying exam (15-min private seminar); thesis + oral defense; MD/PhD track available",
        "ddl": "Fall 2027: **Priority Nov 15, 2026; Final Dec 1, 2026**. Post-Nov 15 still reviewed but no priority funding; interviews late Jan; offers late Feb; April 15 CGS reply.",
        "lang": "TOEFL iBT 80 (sectional 22/22/7/23) or IELTS Academic 7.0; ETS Dartmouth 2519; English-medium exempts.",
        "test_cls": "GRE NOT LISTED AS REQUIRED (Guarini: GRE required by specific program; MCB does not list GRE in current cycle). Subject tests not required. 3 LOR; SOP; CV; transcripts; strong biology/chem/math background.",
        "tui": "Full funding through Guarini School (tuition + stipend + health insurance) via RA/TA/fellowships; guaranteed 5-year support contingent on good standing.",
        "overview": "The Dartmouth Molecular and Cellular Biology (MCB) Graduate Program is an interdepartmental PhD training program spanning four home departments: Biological Sciences, Biochemistry & Cell Biology, Cancer Biology (Geisel School of Medicine), and Microbiology & Immunology. The program admits only full-time PhD students; no terminal MS is offered. First-year students complete three research rotations across the four departments before selecting a thesis advisor by the start of the second year. The qualifying examination consists of a private 15-minute seminar (≤10 slides) presenting the proposed dissertation work to a QE committee, followed by defense of a research proposal. The program also includes a required one term of teaching, research-in-progress seminars, and journal club attendance. MD/PhD students may enter through the combined program.",
        "requirements": "<ul><li>Bachelor's degree or equivalent in biological sciences / chemistry / related field</li><li>GRE NOT required (Guarini: program-specific; MCB does not list GRE in current cycle)</li><li>TOEFL iBT 80 / IELTS 7.0 (non-native English); ETS 2519; English-medium exempts</li><li>Guarini School online application</li><li>Statement of Purpose (research interests, fit with MCB faculty, career goals)</li><li>3 letters of recommendation</li><li>Curriculum vitae</li><li>Transcripts from all post-secondary institutions</li><li>**Priority Deadline November 15, 2026 (early funding consideration)**</li><li>**Final Deadline December 1, 2026**</li><li>Fall admission only; on-campus residential</li><li>3 required research rotations in first year</li></ul>",
        "research": "<ul><li>Molecular and cellular biology (Biological Sciences home dept)</li><li>Biochemistry and cell biology (Geisel home dept)</li><li>Cancer biology (Geisel home dept)</li><li>Microbiology and immunology (Geisel home dept)</li><li>Genetics and molecular systems biology</li><li>Neuroscience</li><li>Structural biology and biophysics</li><li>Developmental biology</li><li>Interdisciplinary with Dartmouth-Hitchcock Medical Center</li></ul>",
        "source": '<a href="https://graduate.dartmouth.edu/admissions/applying-dartmouth" target="_blank">Dartmouth Guarini Applying (MCB PhD: Dec 1 deadline; Priority Nov 15; programs list table)</a> | <a href="https://sites.dartmouth.edu/mcb-biology/" target="_blank">Dartmouth MCB Graduate Program (Biological Sciences / Biochemistry / Cancer Biology / Microbiology home departments; 3 rotations; QE 15-min seminar; teaching requirement)</a> | <a href="https://graduate.dartmouth.edu/mcb/sites/graduate_mcb.prod/files/mcb/wysiwyg/mcb_program_rules_and_regs_2026.pdf" target="_blank">MCB Program Rules &amp; Regs 2026 (7 PhD requirements: rotations, courses, teaching, QE, thesis, seminar, final thesis; full-time PhD only)</a>',
    },
    "ubc-zoology-phd": {
        "school": "University of British Columbia Department of Zoology (Faculty of Science)",
        "en": "PhD in Zoology",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Life Sciences / CIP 26.xx)",
        "dur": "4-5 years full-time residential; fall primary with January/May intakes; **supervisor must agree before application**; supervisory committee of 3 faculty; thesis proposal + oral defense",
        "ddl": "Fall 2027 (Sept): opens Sept 1, 2026. **International deadline January 4, 2027; Canadian deadline January 4, 2027**. Transcript deadline Jan 4; Referee deadline Jan 10. January 2028 intake: opens Jan 1, 2027, deadline July 15, 2027.",
        "lang": "TOEFL iBT 90 (pre-1/21/26; sectional 22/22/22/22) or 4.5 (post-1/21/26); IELTS 6.5 (sectional 6.0); Duolingo DET 125 (sectional 115/120/120/115); English-medium exempts.",
        "test_cls": "GRE NOT REQUIRED (UBC Zoology PhD: 'The GRE is not required.' Subject tests not required. 2 LOR (faculty who directly supervised research); CV; transcripts; minimum B+ average last 2 years).",
        "tui": "UBC graduate support through departmental RA/TA and fellowships (minimum stipend set by Faculty of Graduate + Postdoctoral Studies; international differential waived through assistantships). Application fee ~$150 CAD.",
        "overview": "The UBC Department of Zoology offers a research-based PhD in Zoology on the Vancouver campus. Research spans the full range of animal biology: behavior, ecology, evolution, physiology, developmental biology, marine biology, and biodiversity. The PhD program requires a research supervisor who is a UBC faculty member; admission is contingent on that supervisor agreeing to accept the student and provide funding. Students work with a 3-person supervisory committee and complete a thesis proposal and oral defense. Botany PhD (separate department) is a parallel track for plant science; combined Ecology & Evolutionary Biology research often spans both departments.",
        "requirements": "<ul><li>Bachelor's degree or equivalent in biological sciences; minimum B+ average in last 2 years of study</li><li>GRE NOT required (Zoology PhD explicitly states GRE not required)</li><li>TOEFL iBT 90 / IELTS 6.5 / Duolingo DET 125 (non-native English; scores within 2 years); English-medium exempts</li><li>UBC Graduate and Postdoctoral Studies online application</li><li>CV</li><li>**2 letters of recommendation (ideally faculty who directly supervised your research)**</li><li>Scanned/unofficial transcripts from all post-secondary institutions</li><li>**Supervisor must be identified and must agree to accept before application**</li><li>International deadline January 4, 2027</li><li>Transcript deadline January 4, 2027; Referee deadline January 10, 2027</li><li>Fall primary intake; January/May also available</li></ul>",
        "research": "<ul><li>Animal behavior and neurobiology</li><li>Ecology and evolutionary biology</li><li>Animal physiology and biomechanics</li><li>Developmental biology and genetics</li><li>Marine biology and ocean sciences</li><li>Conservation biology and biodiversity</li><li>Functional morphology and biomechanics</li><li>Interdisciplinary with Botany PhD (separate department)</li><li>UBC Biodiversity Research Centre</li></ul>",
        "source": '<a href="https://www.grad.ubc.ca/prospective-students/graduate-degree-programs/phd-zoology" target="_blank">UBC PhD in Zoology (GRE not required; TOEFL 90 / IELTS 6.5 / DET 125; 2 LOR; CV; transcripts; international deadline Jan 4, 2027; referee deadline Jan 10, 2027)</a> | <a href="https://www.grad.ubc.ca/prospective-students/application-admission?dl=746&page=2" target="_blank">UBC Application Deadlines (PhD Zoology Sept 2027: Canadian and International both January 4, 2027; Botany PhD Jan 10, 2027)</a> | <a href="https://www.zoology.ubc.ca/" target="_blank">UBC Department of Zoology (supervisor must be confirmed before application; Vancouver campus; marine/behavior/ecology/physiology research)</a>',
    },
    "mcg-biology-phd": {
        "school": "McGill University Department of Biology (Faculty of Science)",
        "en": "PhD in Biology",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Life Sciences / CIP 26.xx)",
        "dur": "4-5 years full-time residential; **supervisor must be confirmed before application**; PhD1 (direct from BSc, CGPA 3.5+) or PhD2 (MSc entry); 2 LOR with institutional email; McGill Harmonized Funding Policy guarantees minimum stipend",
        "ddl": "Fall 2027 (Sept): opens Sept 15. **International deadline January 15, 2027; Canadian/PR deadline February 15, 2027**. Winter 2028 (Jan): opens Feb 15, international deadline August 1, domestic November 1. **Summer admission NOT offered**.",
        "lang": "TOEFL iBT 86 (each component no less than 20) or IELTS Academic 6.5; ETS McGill 0935; English-medium / Canadian institution exempts; scores within 2 years.",
        "test_cls": "GRE NOT REQUIRED (McGill Biology: 'GRE General Test not required.' Subject tests not required. 2 LOR (institutional email required - gmail/yahoo/hotmail not accepted); CV; Personal Statement; transcripts; minimum CGPA 3.0/4.0 (or 3.2 last 2 years); direct BSc entry to PhD1 requires CGPA 3.5/4.0).",
        "tui": "McGill Harmonized Funding Policy: guaranteed minimum stipend package (stipend + tuition offset) for Biology PhD for 4 years; support via supervisor grants, RA/TA, McGill Fellowships (Quebec Excellence, NSERC). Application fee ~$126 CAD.",
        "overview": "The McGill University PhD in Biology is a research-intensive program offered by the Department of Biology in the Faculty of Science. Research themes cluster in three areas: (1) molecular, cellular, and developmental biology; (2) conservation, ecology, and evolution; and (3) neurobiology and behavior. The program may also be taken with the optional Neotropical Environment option, where students conduct research in Latin America and take core/complementary courses in Panama (Smithsonian Tropical Research Institute). Admission is based on evaluation by the Graduate Training Committee AND acceptance by a faculty member who agrees to supervise and fund the applicant. Two entry points exist: PhD1 (direct from BSc with CGPA 3.5+) and PhD2 (MSc entry). Summer admission is not offered.",
        "requirements": "<ul><li>Bachelor's degree (PhD2 entry) or MSc (PhD2 entry); minimum CGPA 3.0/4.0 (or 3.2 in last 2 full-time years)</li><li>**Direct BSc to PhD1 fast-track requires CGPA 3.5/4.0**</li><li>GRE NOT required (McGill Biology explicitly states GRE not required)</li><li>TOEFL iBT 86 (each component no less than 20) / IELTS 6.5 (non-native English); ETS 0935; English-medium/Canadian exempts</li><li>McGill online application</li><li>Personal Statement / Statement of Research Interests</li><li>**2 letters of recommendation (institutional email required - gmail/yahoo/hotmail NOT accepted; must be academic, non-supervisor)**</li><li>Curriculum vitae</li><li>Transcripts</li><li>**Supervisor must be confirmed (Supervisor Confirmation Form required) before admission consideration**</li><li>International deadline January 15, 2027; Canadian/PR deadline February 15, 2027</li><li>Fall and Winter intakes only; **Summer NOT offered**</li></ul>",
        "research": "<ul><li>Molecular, cellular, and developmental biology</li><li>Conservation, ecology, and evolutionary biology</li><li>Neurobiology and behavior</li><li>Neotropical Environment option (Panama / STRI field research)</li><li>Genetics and genomics</li><li>Plant biology and phytotron</li><li>Aquatic ecology and Gault Nature Reserve</li><li>Bellairs Research Institute (Barbados) field station</li><li>Advanced BioImaging Facility (ABIF)</li></ul>",
        "source": '<a href="https://www.mcgill.ca/gradapplicants/program/biology-phd" target="_blank">McGill Biology PhD (Fall: international Jan 15, domestic Feb 15; Winter: international Aug 1, domestic Nov 1; Summer NOT offered; 3 research themes; Neotropical option)</a> | <a href="https://www.mcgill.ca/study/2024-2025/faculties/science/graduate/gps_sci_biology" target="_blank">McGill eCalendar Biology PhD (CGPA 3.0/4.0; direct BSc to PhD1 requires 3.5/4.0; TOEFL 86 / IELTS 6.5; supervisor must agree before application)</a> | <a href="https://www.mcgill.ca/anatomy/graduate/applying/academic-requirements" target="_blank">McGill Anatomy &amp; Cell Biology (reference: 2 LOR; institutional email; GRE not required; ETS 0935; McGill Harmonized Funding Policy)</a>',
    },
    "ut-eeb-phd": {
        "school": "University of Toronto Department of Ecology & Evolutionary Biology (Faculty of Arts & Science)",
        "en": "PhD in Ecology and Evolutionary Biology (EEB)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Life Sciences / CIP 26.xx)",
        "dur": "4 years (5 years for direct entry from BSc); **supervisor must agree before application**; 2 FCE graduate courses (1.5 FCE for MSc-entry); mid-program Appraisal Examination; 2 research seminars; thesis defense; supervisors across all 3 campuses + Royal Ontario Museum",
        "ddl": "Fall 2027 (Sept): SGS portal opens November 6, 2026. **International deadline ~December 9, 2026; Domestic deadline ~January 9, 2027**. Rolling review after deadline until positions filled. January/May entry possible under special circumstances.",
        "lang": "TOEFL iBT 93 (sectional 22/22/22/22) or IELTS Academic 7.0; MELAB / COPE also accepted; English-medium exempts; scores within 2 years; ETS UofT 0982.",
        "test_cls": "GRE NOT REQUIRED (UofT EEB: 'GRE scores are not required.' Subject tests not required. 3 LOR; SOP; CV; transcripts; minimum B+ final year of bachelor's and A- in MSc; direct BSc entry requires A- in EEB courses + strong research potential).",
        "tui": "UofT Science-funded stipend: base $18,000/year + tuition + fees (including UHIP for international) guaranteed for 'funded cohort'; departments may increase but cannot offer less than minimum. **Note: UofT EEB does NOT currently accept MSc applications from international students, but PhD applications from international students ARE accepted.**",
        "overview": "The University of Toronto PhD in Ecology and Evolutionary Biology is offered through the Department of Ecology & Evolutionary Biology on the St. George campus, with supervisory faculty also at U of T Mississauga (UTM) and U of T Scarborough (UTSC), as well as the Royal Ontario Museum. The program requires a research supervisor who agrees to accept and fund the student before application consideration. Three entry routes exist: (1) entry with MSc (average A- during MSc, B+ in final year of bachelor's); (2) transfer from EEB MSc program (limited number, case-by-case); (3) direct entry from BSc (exceptional applicants with A- in EEB courses and strong research potential). PhD students complete 2 FCE graduate courses (1.5 FCE for MSc-entry), a mid-program Appraisal Examination, two research seminars, and a final thesis defense. The funded cohort receives a base stipend of $18,000 plus tuition and fees.",
        "requirements": "<ul><li>Bachelor's degree (direct BSc entry) or MSc (MSc-entry route)</li><li>Minimum B+ average in final year of bachelor's; MSc-entry requires A- average in MSc</li><li>GRE NOT required (UofT EEB explicitly states GRE scores are not required)</li><li>TOEFL iBT 93 / IELTS 7.0 / MELAB / COPE (non-native English; scores within 2 years); ETS 0982; English-medium exempts</li><li>UofT School of Graduate Studies (SGS) online application</li><li>Statement of Research Interests / SOP</li><li>3 letters of recommendation</li><li>Curriculum vitae</li><li>Transcripts</li><li>**Supervisor must agree to accept and fund before application (applicant must contact faculty directly)**</li><li>International deadline ~December 9, 2026; Domestic deadline ~January 9, 2027</li><li>Fall primary; January/May possible under special circumstances</li><li>**Note: EEB does NOT currently accept MSc applications from international students; PhD applications ARE accepted from international students**</li></ul>",
        "research": "<ul><li>Population and community ecology</li><li>Evolutionary biology and genetics</li><li>Behavioral ecology and behavior genetics</li><li>Conservation biology and biodiversity</li><li>Plant biology and taxonomy/systematics</li><li>Developmental biology and evo-devo</li><li>Bioinformatics and theoretical biology</li><li>Microbiology and molecular evolution</li><li>Anatomy/physiology (comparative)</li><li>Supervisory faculty at St. George, UTM, UTSC, and Royal Ontario Museum</li></ul>",
        "source": '<a href="https://eeb.utoronto.ca/education/graduate/graduate-admissions/" target="_blank">UofT EEB Graduate Admissions (supervisor before admission; GRE not required; TOEFL/IELTS; portal opens Nov 6; international Dec 9, domestic Jan 9)</a> | <a href="https://www.sgs.utoronto.ca/programs/ecology-and-evolutionary-biology/" target="_blank">UofT SGS: Ecology &amp; Evolutionary Biology (MSc/PhD; direct BSc entry; supervisor identified before admission; MSc not open to international applicants currently)</a> | <a href="https://eeb.utoronto.ca/education/graduate/graduate-program-requirements/" target="_blank">UofT EEB Program Requirements (base stipend $18,000 + tuition/fees; Appraisal Exam; 2 research seminars; 2 FCE coursework; 4-5 years; supervisors across 3 campuses + ROM)</a>',
    },
    "uw-biology-phd": {
        "school": "University of Waterloo Department of Biology (Faculty of Science)",
        "en": "PhD in Biology (optional Collaborative Water Program specialization)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Life Sciences / CIP 26.xx)",
        "dur": "4 years (48 months) full-time residential; **strongly advise supervisor contact before applying**; MSc-to-PhD transfer possible case-by-case; thesis-based research; Water specialization includes 2 interdisciplinary water courses + fieldwork + interdisciplinary group work",
        "ddl": "Rolling admission for Fall (Sept), Winter (Jan), Spring (May). International applicants advised to apply 6-8 months before intended start; domestic 3-4 months. **Recommended target: February 1, 2027 for Fall 2027 September entry** (competitive funding consideration); applications reviewed continuously until supervisor-funded positions filled.",
        "lang": "TOEFL iBT 90 (writing 25, speaking 25, reading/listening 22) or IELTS Academic 7.0 (writing 6.5, speaking 6.5); Duolingo DET also accepted; English-medium exempts; scores within 2 years; ETS Waterloo 0996.",
        "test_cls": "GRE NOT REQUIRED (Waterloo Biology Department does not require GRE for PhD admission. Subject tests not required. 3 LOR; CV; Statement of Research Interests; transcripts; minimum 75% overall standing in relevant MSc; direct BSc entry requires superior academic record + strong research experience).",
        "tui": "Waterloo graduate support through supervisor research grants, teaching assistantships, and Waterloo Graduate Scholarships (minimum stipend package; international differential tuition). Research-focused MSc/PhD track. Application fee ~$125 CAD.",
        "overview": "The University of Waterloo Department of Biology offers research-based MSc and PhD programs in Biology. The PhD program is thesis-based and designed for students who want to conduct fundamental research in biological systems. The optional Collaborative Water Program specialization is coordinated by the Waterloo Water Institute across 11 academic units; students in this track complete two interdisciplinary water courses (theoretical + practical components, including in-class lectures, fieldwork, interdisciplinary group work, and individual research seminars). Admission is rolling across September, January, and May intakes; applicants are strongly advised to establish contact with a potential supervisor before applying, since admission is contingent on supervisor-funded positions. Transfer from MSc to PhD is possible on a case-by-case basis for suitably qualified students.",
        "requirements": "<ul><li>Bachelor's degree or MSc in biology or related science</li><li>Minimum 75% overall standing in relevant MSc (or equivalent); direct BSc entry requires superior academic record and strong research experience</li><li>GRE NOT required (Waterloo Biology Department does not require GRE)</li><li>TOEFL iBT 90 (writing 25, speaking 25) / IELTS 7.0 (writing 6.5, speaking 6.5) / Duolingo DET; ETS 0996; English-medium exempts</li><li>Waterloo online application</li><li>Statement of Research Interests</li><li>3 letters of reference</li><li>CV / resume</li><li>Transcripts</li><li>**Strongly advise establishing contact with potential supervisor before applying (admission contingent on supervisor-funded positions)**</li><li>Rolling admission: Fall (Sept), Winter (Jan), Spring (May)</li><li>Recommended Feb 1, 2027 for Fall 2027 competitive funding consideration</li><li>Water specialization optional (Collaborative Water Program)</li></ul>",
        "research": "<ul><li>Molecular and cell biology</li><li>Ecology and evolutionary biology</li><li>Physiology and organismal biology</li><li>Microbiology and environmental biology</li><li>Plant biology and agriculture</li><li>Water science (Collaborative Water Program specialization)</li><li>Biotechnology and synthetic biology</li><li>Interdisciplinary with Waterloo Institute for Sustainable Aeronautics (Vision Science cross-program)</li><li>Field stations and water research facilities</li></ul>",
        "source": '<a href="https://uwaterloo.ca/science/future-graduate-students/graduate-programs" target="_blank">Waterloo Science Graduate Programs (Biology MSc/PhD; Biology - Water specialization; contact: April Wettig awettig@uwaterloo.ca)</a> | <a href="https://www.schoolfinder.com/Programs/117326/Biology-(Water)-Doctor-of-Philosophy-(PhD)" target="_blank">Waterloo Biology (Water) PhD (48 months; 75% MSc standing; 2 interdisciplinary water courses; fieldwork; group work; contact supervisor before applying)</a> | <a href="https://uwaterloo.ca/biology/" target="_blank">Waterloo Department of Biology (research-based MSc/PhD; rolling admission; supervisor-linked funding)</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)}")
