feat: auto-scrape on product creation and update product data (Step 4)
- Add automatic scraping when creating a new product
- Update product title and image from scraped data
- Add GET /products/{id}/snapshots endpoint for price history
- Add list_snapshots and get_latest_snapshot to CRUD
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,20 @@ def _save_debug_artifacts(page, product_id: int) -> tuple[Path, Path]:
|
||||
return screenshot_path, html_path
|
||||
|
||||
|
||||
def _update_product_from_scrape(
|
||||
session: Session,
|
||||
product: models.Product,
|
||||
data: dict,
|
||||
) -> None:
|
||||
"""Met à jour le produit avec les données scrappées (titre, image)."""
|
||||
if data.get("titre") and not product.titre:
|
||||
product.titre = data["titre"]
|
||||
if data.get("url_image_principale") and not product.url_image:
|
||||
product.url_image = data["url_image_principale"]
|
||||
session.add(product)
|
||||
session.commit()
|
||||
|
||||
|
||||
def _create_snapshot(
|
||||
session: Session,
|
||||
product: models.Product,
|
||||
@@ -62,6 +76,9 @@ def _create_snapshot(
|
||||
raw_json_path: Path | None,
|
||||
error_message: str | None = None,
|
||||
) -> None:
|
||||
# Mettre à jour le produit avec titre/image si manquants
|
||||
_update_product_from_scrape(session, product, data)
|
||||
|
||||
snapshot = models.ProductSnapshot(
|
||||
produit_id=product.id,
|
||||
run_scrap_id=run.id,
|
||||
|
||||
Reference in New Issue
Block a user