Add services layer, tests, streaming UI, and cleanup legacy code
This commit is contained in:
parent
5514fa6381
commit
d205d15c74
62 changed files with 3729 additions and 1024 deletions
38
crawler/services/district_service.py
Normal file
38
crawler/services/district_service.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""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())
|
||||
|
||||
|
||||
def validate_districts(district_names: list[str]) -> tuple[bool, list[str]]:
|
||||
"""Validate that district names exist.
|
||||
|
||||
Args:
|
||||
district_names: List of district names to validate
|
||||
|
||||
Returns:
|
||||
Tuple of (all_valid, invalid_names)
|
||||
"""
|
||||
valid_districts = set(_get_districts().keys())
|
||||
invalid = [d for d in district_names if d not in valid_districts]
|
||||
return len(invalid) == 0, invalid
|
||||
Loading…
Add table
Add a link
Reference in a new issue