#!/usr/bin/env python3
"""Generate results/index.html — a landing page linking to every dashboard
in the results/ directory. Rerun anytime new dashboards are added."""
import os, re, html
RESULTS = "/home/user/polisci/results"
# Metadata for each dashboard (name, party, chamber, district/state).
# Anything not listed here is auto-rendered with just the filename.
META = {
"ThomasMassie119.html": ("Thomas Massie", "R", "House", "KY-4"),
"RoKhanna119.html": ("Ro Khanna", "D", "House", "CA-17"),
"AlexandriaOcasioCortez119.html":("Alexandria Ocasio-Cortez", "D", "House", "NY-14"),
"IlhanOmar119.html": ("Ilhan Omar", "D", "House", "MN-5"),
"MarjorieTaylorGreene119.html": ("Marjorie Taylor Greene", "R", "House", "GA-14"),
"JimJordan119.html": ("Jim Jordan", "R", "House", "OH-4"),
"ByronDonalds119.html": ("Byron Donalds", "R", "House", "FL-19"),
"LindseyGraham119.html": ("Lindsey Graham", "R", "Senate", "SC"),
}
PARTY_COLOR = {"R": "#d93b3b", "D": "#3b6ed9", "I": "#888"}
CHAMBER_COLOR = {"House": "#1e6b1e", "Senate": "#5a3d8a"}
def main():
files = sorted(f for f in os.listdir(RESULTS) if f.endswith(".html") and f != "index.html")
cards = []
for f in files:
meta = META.get(f)
if meta:
name, party, chamber, loc = meta
else:
name = re.sub(r"119\.html$", "", f)
party, chamber, loc = "?", "?", ""
pc = PARTY_COLOR.get(party, "#888")
cc = CHAMBER_COLOR.get(chamber, "#888")
cards.append(f"""