Fix: Deep fix for Action.com availability false positives. Advanced title normalization and clarified unavailability detection logic. Optimized ActionParser.

This commit is contained in:
Michael committed 2026-01-13 13:56:12 +01:00
1 parent 8329eb28a3
commit 4a686e1b86
3 files changed
+74 -36

No files matched your search

+30 -1
View File
@@ -54,10 +54,17 @@ def _normalize_title(title: str) -> str:
title = re.sub(r"([a-zA-Z])(\d)", r"\1 \2", title)
title = re.sub(r"(\d)([a-zA-Z])", r"\1 \2", title)
# Remove extra spaces and punctuation that might differ between sites
# Remove non-word characters (punctuation) early to simplify regex
title = re.sub(r"[^\w\s]", " ", title)
title = " ".join(title.split())
# Remove technical metadata at the end (Action specific noise)
# Match various patterns like "0 09 pce 342" or "100 pièces" etc.
title = re.sub(r"\s+\d+\s+\d+\s+pce.*$", "", title)
title = re.sub(r"\s+\d+\s+pièces.*$", "", title)
title = re.sub(r"\s+\d+\s+€.*$", "", title)
title = re.sub(r"\s+\d+\s+\d+\s+€.*$", "", title)
return title.strip()
@@ -363,6 +370,28 @@ async def process_item_check(item_id: int):
f"Stored: '{item_data['name']}', Page title: '{page_title}'"
)
# For Action.com, if we haven't confirmed unavailability above,
# don't mark as unavailable yet, just mark as potential replacement error
# unless the title is almost completely different
if is_action:
# Check if at least some significant words match
norm_stored = _normalize_title(item_data["name"])
norm_page = _normalize_title(page_title)
stored_words = set(norm_stored.split())
page_words = set(norm_page.split())
intersection = stored_words & page_words
if len(intersection) >= 2 or (len(stored_words) <= 3 and len(intersection) >= 1):
logger.warning(
f"Borderline title match for Action.com item {item_id}. Keeping as available but marking error."
)
await loop.run_in_executor(
None,
_update_db_error,
item_id,
f"Titre différent mais produit probablement correct : {page_title}",
)
return
await loop.run_in_executor(
None,
_update_db_product_unavailable,