mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-24 07:38:13 +02:00
Merge pull request #28 from R0m1k3/claude/design-product-search-01Ea9dWZqZpuKFwBwVmp26PG
fix: Fix AI service call and domain URL building
This commit is contained in:
2 files changed
+46
-17
No files matched your search
@@ -118,7 +118,10 @@ async def _search_site_browserless(
|
|||||||
timeout: float,
|
timeout: float,
|
||||||
) -> list[SearchResult]:
|
) -> list[SearchResult]:
|
||||||
"""Recherche sur un site via Browserless (Playwright)"""
|
"""Recherche sur un site via Browserless (Playwright)"""
|
||||||
domain = site.get("domain", "").lower()
|
raw_domain = site.get("domain", "").lower()
|
||||||
|
# Nettoyer le domaine (enlever protocole, www, slash final)
|
||||||
|
domain = _clean_domain(raw_domain)
|
||||||
|
|
||||||
search_url = site.get("search_url") or _get_default_search_url(domain)
|
search_url = site.get("search_url") or _get_default_search_url(domain)
|
||||||
product_selector = site.get("product_link_selector") or _get_default_product_selector(domain)
|
product_selector = site.get("product_link_selector") or _get_default_product_selector(domain)
|
||||||
wait_selector = _get_default_wait_selector(domain)
|
wait_selector = _get_default_wait_selector(domain)
|
||||||
@@ -358,6 +361,29 @@ def _extract_domain(url: str) -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def _clean_domain(domain: str) -> str:
|
||||||
|
"""Nettoie un domaine (enlève protocole, www, slash final)"""
|
||||||
|
if not domain:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
domain = domain.strip().lower()
|
||||||
|
|
||||||
|
# Enlever le protocole
|
||||||
|
if domain.startswith("https://"):
|
||||||
|
domain = domain[8:]
|
||||||
|
elif domain.startswith("http://"):
|
||||||
|
domain = domain[7:]
|
||||||
|
|
||||||
|
# Enlever www.
|
||||||
|
if domain.startswith("www."):
|
||||||
|
domain = domain[4:]
|
||||||
|
|
||||||
|
# Enlever le slash final
|
||||||
|
domain = domain.rstrip("/")
|
||||||
|
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
def _is_non_product_url(url: str) -> bool:
|
def _is_non_product_url(url: str) -> bool:
|
||||||
"""Vérifie si l'URL n'est pas une page produit"""
|
"""Vérifie si l'URL n'est pas une page produit"""
|
||||||
non_product_patterns = [
|
non_product_patterns = [
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
from app.models import SearchSite
|
from app.models import SearchSite
|
||||||
from app.schemas import SearchProgress, SearchResultItem
|
from app.schemas import SearchProgress, SearchResultItem
|
||||||
from app.services import ai_service, direct_search_service, light_scraper_service
|
from app.services import direct_search_service, light_scraper_service
|
||||||
|
from app.services.ai_service import AIService
|
||||||
from app.services.scraper_service import ScraperService
|
from app.services.scraper_service import ScraperService
|
||||||
from app.services.settings_service import SettingsService
|
from app.services.settings_service import SettingsService
|
||||||
|
|
||||||
@@ -227,23 +228,25 @@ async def _scrape_with_browserless(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Extraction IA
|
# Extraction IA
|
||||||
ai_result = await ai_service.analyze_image(
|
ai_result = await AIService.analyze_image(
|
||||||
screenshot_path=screenshot_path,
|
image_path=screenshot_path,
|
||||||
webpage_text=page_text,
|
page_text=page_text,
|
||||||
)
|
)
|
||||||
|
|
||||||
if ai_result and ai_result.get("price"):
|
if ai_result:
|
||||||
return SearchResultItem(
|
extraction, metadata = ai_result
|
||||||
url=url,
|
if extraction and extraction.price is not None:
|
||||||
title=fallback_title,
|
return SearchResultItem(
|
||||||
price=ai_result.get("price"),
|
url=url,
|
||||||
currency=ai_result.get("currency", "EUR"),
|
title=fallback_title,
|
||||||
in_stock=ai_result.get("in_stock"),
|
price=extraction.price,
|
||||||
image_url=None, # Pas d'image depuis le screenshot
|
currency=extraction.currency or "EUR",
|
||||||
site_name=site_name,
|
in_stock=extraction.in_stock,
|
||||||
site_domain=domain,
|
image_url=None,
|
||||||
confidence=ai_result.get("price_confidence", 0.5),
|
site_name=site_name,
|
||||||
)
|
site_domain=domain,
|
||||||
|
confidence=extraction.price_confidence or 0.5,
|
||||||
|
)
|
||||||
|
|
||||||
return SearchResultItem(
|
return SearchResultItem(
|
||||||
url=url,
|
url=url,
|
||||||
|
|||||||
Reference in new issue
Block a user