2026-02-06 20:55:10 +00:00
|
|
|
"""Unified district service - shared between CLI and HTTP API."""
|
|
|
|
|
from rec.districts import get_districts as _get_districts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_districts() -> dict[str, str]:
|
|
|
|
|
"""Get all available districts with their region IDs.
|
|
|
|
|
|
|
|
|
|
Used by:
|
|
|
|
|
- CLI: --district option choices
|
|
|
|
|
- API: GET /api/get_districts
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Dictionary mapping district names to region IDs
|
|
|
|
|
"""
|
|
|
|
|
return _get_districts()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_district_names() -> list[str]:
|
|
|
|
|
"""Get list of all district names.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of district names
|
|
|
|
|
"""
|
|
|
|
|
return list(_get_districts().keys())
|
|
|
|
|
|
|
|
|
|
|
2026-02-07 20:19:57 +00:00
|
|
|
def validate_districts(district_names: list[str]) -> list[str]:
|
2026-02-06 20:55:10 +00:00
|
|
|
"""Validate that district names exist.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
district_names: List of district names to validate
|
|
|
|
|
|
|
|
|
|
Returns:
|
2026-02-07 20:19:57 +00:00
|
|
|
List of invalid district names (empty if all valid)
|
2026-02-06 20:55:10 +00:00
|
|
|
"""
|
|
|
|
|
valid_districts = set(_get_districts().keys())
|
2026-02-07 20:19:57 +00:00
|
|
|
return [d for d in district_names if d not in valid_districts]
|