From e6b64d6efec6586c711591aac8fe3dba4b9c0f7d Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Thu, 9 Apr 2026 20:24:26 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20imitate=20extractor=20+=20health=5Fpath?= =?UTF-8?q?=20=E2=80=94=20support=20CF=20cloud=20API=20shapes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _extract_sample: add saved_searches, entries, calls, records as recognized list-wrapper keys (snipe/osprey response shapes) - _is_online: accept health_path param (default /api/health) so products using /api/v1/health/ (kiwi) report correctly - products endpoint: pass health_path from config into _is_online --- app/imitate.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/imitate.py b/app/imitate.py index a42915d..44b4e79 100644 --- a/app/imitate.py +++ b/app/imitate.py @@ -94,10 +94,10 @@ def _http_get_json(url: str, timeout: int = 5) -> Any: return json.loads(resp.read().decode("utf-8")) -def _is_online(base_url: str) -> bool: - """Return True if the product's /api/health endpoint responds OK.""" +def _is_online(base_url: str, health_path: str = "/api/health") -> bool: + """Return True if the product's health endpoint responds OK.""" try: - data = _http_get_json(f"{base_url.rstrip('/')}/api/health", timeout=2) + data = _http_get_json(f"{base_url.rstrip('/')}{health_path}", timeout=2) return bool(data) except Exception: return False @@ -114,7 +114,8 @@ def _extract_sample( item = raw[min(sample_index, len(raw) - 1)] elif isinstance(raw, dict): # may be {items: [...]} or the item itself - for key in ("items", "results", "data", "jobs", "listings", "pantry"): + for key in ("items", "results", "data", "jobs", "listings", "pantry", + "saved_searches", "entries", "calls", "records"): if key in raw and isinstance(raw[key], list): lst = raw[key] item = lst[min(sample_index, len(lst) - 1)] if lst else {} @@ -189,7 +190,7 @@ def get_products() -> dict: "icon": p.get("icon", "📦"), "description": p.get("description", ""), "base_url": base_url, - "online": _is_online(base_url) if base_url else False, + "online": _is_online(base_url, p.get("health_path", "/api/health")) if base_url else False, }) return {"products": products}