#!/usr/bin/env python3 """One-off: create data/counties/.yaml for all 67 Alabama counties. Alabama county FIPS codes are the odd numbers 001..133 in alphabetical order, so they can be computed. Run from the repo root: python scripts/make_county_stubs.py Existing files are never overwritten, so it is safe to re-run. """ from pathlib import Path import yaml # Same regions as the Discord bot's data.py REGIONS = { "North": "Lauderdale, Colbert, Franklin, Marion, Lamar, Madison, Limestone, Morgan, " "Lawrence, Cullman, Winston, Jackson, Marshall, DeKalb, Cherokee, Etowah", "West": "Bibb, Choctaw, Fayette, Greene, Hale, Marengo, Pickens, Sumter, Tuscaloosa, Perry", "South": "Mobile, Baldwin, Houston, Dale, Coffee, Geneva, Henry, Covington, Escambia, " "Conecuh, Monroe, Clarke, Washington, Pike, Barbour, Butler, Crenshaw, Wilcox", "Central": "Jefferson, Shelby, Saint Clair, Blount, Walker, Montgomery, Autauga, Elmore, " "Chilton, Dallas, Lowndes", "East": "Lee, Russell, Chambers, Tallapoosa, Randolph, Macon, Calhoun, Cleburne, Clay, " "Talladega, Coosa, Bullock", } region_of = { name.strip(): region for region, names in REGIONS.items() for name in names.split(",") } assert len(region_of) == 67, len(region_of) out = Path("data/counties") out.mkdir(parents=True, exist_ok=True) for i, name in enumerate(sorted(region_of)): slug = name.lower().replace(" ", "-") record = { "name": name, "slug": slug, "fips": f"01{2 * i + 1:03d}", "region": region_of[name], } if name == "DeKalb": assert record["fips"] == "01049" # sanity check on the numbering path = out / f"{slug}.yaml" if not path.exists(): path.write_text(yaml.safe_dump(record, sort_keys=False), encoding="utf-8") print(f"{len(list(out.glob('*.yaml')))} county files in {out}/")