fix car mapping

This commit is contained in:
qananasikq
2026-07-01 13:49:30 +03:00
parent 6a46b2f022
commit a4d0f35279
4 changed files with 399 additions and 7 deletions

View File

@@ -222,7 +222,7 @@ class AlgoliaConfig:
index_name: str = _env_str("DUBIZZLE_ALGOLIA_INDEX_NAME", "motors.com")
category_slug: str = _env_str("DUBIZZLE_ALGOLIA_CATEGORY_SLUG", "motors/used-cars")
base_url: str = _env_str("DUBIZZLE_ALGOLIA_BASE_URL", "https://WD0PTZ13ZS-dsn.algolia.net")
hits_per_page: int = _env_int("DUBIZZLE_ALGOLIA_HITS_PER_PAGE", 100)
hits_per_page: int = _env_int("DUBIZZLE_ALGOLIA_HITS_PER_PAGE", 20)
# --- Конфиг Celery (лимиты задач, concurrency, beat-расписание) ---

View File

@@ -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,