fix car mapping
This commit is contained in:
@@ -99,11 +99,22 @@ class _AlgoliaHttpClient:
|
||||
},
|
||||
method="POST",
|
||||
)
|
||||
with urlopen(request, timeout=30) as response:
|
||||
body = response.read().decode("utf-8", errors="ignore")
|
||||
parsed = json.loads(body)
|
||||
results = parsed.get("results") or []
|
||||
return results[0] if results and isinstance(results[0], dict) else {}
|
||||
|
||||
last_exc: Exception | None = None
|
||||
for attempt in range(1, 4):
|
||||
try:
|
||||
with urlopen(request, timeout=15) as response:
|
||||
body = response.read().decode("utf-8", errors="ignore")
|
||||
parsed = json.loads(body)
|
||||
results = parsed.get("results") or []
|
||||
return results[0] if results and isinstance(results[0], dict) else {}
|
||||
except Exception as exc:
|
||||
last_exc = exc
|
||||
if attempt >= 3:
|
||||
break
|
||||
time.sleep(0.8 * attempt)
|
||||
|
||||
raise last_exc or RuntimeError("Algolia request failed")
|
||||
|
||||
|
||||
def _build_origin_id_from_hit(hit: dict[str, Any]) -> str | None:
|
||||
@@ -282,6 +293,7 @@ def _fetch_shard_hits(
|
||||
year_min: int | None,
|
||||
year_max: int | None,
|
||||
known_origin_ids: set[str] | None,
|
||||
limit: int | None,
|
||||
threshold: float,
|
||||
max_duration_seconds: float | None,
|
||||
started_at: float,
|
||||
@@ -347,6 +359,12 @@ def _fetch_shard_hits(
|
||||
hit_records[url] = raw_hit
|
||||
if origin_id:
|
||||
origin_ids_by_url[url] = origin_id
|
||||
if limit is not None and limit > 0 and len(urls) >= limit:
|
||||
early_stopped = True
|
||||
break
|
||||
|
||||
if limit is not None and limit > 0 and len(urls) >= limit:
|
||||
break
|
||||
|
||||
if known_origin_ids is not None and threshold > 0 and (page_known + page_new) > 0:
|
||||
ratio = page_known / (page_known + page_new)
|
||||
@@ -438,6 +456,7 @@ def discover_vehicle_hits_from_algolia(
|
||||
year_min=year_min,
|
||||
year_max=year_max,
|
||||
known_origin_ids=known_origin_ids,
|
||||
limit=(limit - len(collected_urls)) if limit is not None and limit > 0 else None,
|
||||
threshold=threshold,
|
||||
max_duration_seconds=max_duration_seconds,
|
||||
started_at=started_at,
|
||||
|
||||
Reference in New Issue
Block a user