Show source location (city/state/zip) in list_sources output
/api/data/sources now returns per-source geo; surface it as a Location column in the sources table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+11
-3
@@ -302,18 +302,26 @@ def fmt_basis_detail(payload: dict, max_rows: int = 80) -> str:
|
||||
# ---------- sources / health ----------
|
||||
|
||||
|
||||
def _location(s: dict) -> str:
|
||||
city, state = s.get("city"), s.get("state")
|
||||
loc = ", ".join(p for p in (city, state) if p)
|
||||
if s.get("zip"):
|
||||
loc = f"{loc} {s['zip']}".strip()
|
||||
return loc or "—"
|
||||
|
||||
|
||||
def fmt_sources(payload: dict) -> str:
|
||||
src = payload.get("sources") or []
|
||||
if not src:
|
||||
return "### Sources\n\nNo active sources.\n"
|
||||
lines = [
|
||||
"### Tracked sources", "",
|
||||
"| Source | Kind | Last success | Consecutive failures | Last error |",
|
||||
"|---|---|---|---:|---|",
|
||||
"| Source | Kind | Location | Last success | Consecutive failures | Last error |",
|
||||
"|---|---|---|---|---:|---|",
|
||||
]
|
||||
for s in src:
|
||||
lines.append(
|
||||
f"| {s['name']} | {s['kind']} | {s.get('last_success_at') or '—'} | "
|
||||
f"| {s['name']} | {s['kind']} | {_location(s)} | {s.get('last_success_at') or '—'} | "
|
||||
f"{s.get('consecutive_failures') or 0} | {s.get('last_error') or ''} |"
|
||||
)
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
@@ -200,12 +200,14 @@ def test_fmt_basis_detail_per_series():
|
||||
def test_fmt_sources_table():
|
||||
payload = {"sources": [
|
||||
{"id": 1, "name": "Test Elev", "kind": "elevator",
|
||||
"city": "Ada", "state": "OH", "zip": "45810",
|
||||
"last_success_at": "2026-05-20T14:55:00+00:00",
|
||||
"consecutive_failures": 0, "last_error": None},
|
||||
]}
|
||||
out = fmt.fmt_sources(payload)
|
||||
assert "Test Elev" in out
|
||||
assert "elevator" in out
|
||||
assert "Ada, OH 45810" in out # location column
|
||||
|
||||
|
||||
def test_fmt_health_buckets():
|
||||
|
||||
Reference in New Issue
Block a user