This commit is contained in:
2026-01-25 14:48:26 +01:00
parent 5c3e6b84a4
commit c56a4632a2
958 changed files with 1149102 additions and 123 deletions

View File

@@ -63,6 +63,7 @@ def create_product_with_snapshot(
"description",
"carateristique",
"details",
"categorie_amazon",
]
snapshot_data = {k: data_dict.pop(k) for k in snapshot_fields if k in data_dict}
@@ -118,15 +119,23 @@ def remove_product(db: Session, product: models.Product) -> None:
db.commit()
def list_snapshots(db: Session, product_id: int, limit: int = 30) -> list[models.ProductSnapshot]:
return (
db.query(models.ProductSnapshot)
.filter(models.ProductSnapshot.produit_id == product_id)
.order_by(models.ProductSnapshot.scrape_le.desc())
.limit(limit)
.all()
def list_snapshots(
db: Session, product_id: int, days: int | None = None, limit: int = 1000
) -> list[models.ProductSnapshot]:
"""Retourne les snapshots d'un produit, filtrés par nombre de jours si spécifié."""
from datetime import datetime, timedelta
query = db.query(models.ProductSnapshot).filter(
models.ProductSnapshot.produit_id == product_id
)
# Filtrer par date si days est spécifié
if days is not None and days > 0:
cutoff_date = datetime.utcnow() - timedelta(days=days)
query = query.filter(models.ProductSnapshot.scrape_le >= cutoff_date)
return query.order_by(models.ProductSnapshot.scrape_le.desc()).limit(limit).all()
def get_latest_snapshot(db: Session, product_id: int) -> models.ProductSnapshot | None:
return (
@@ -215,6 +224,7 @@ def _enrich_product_with_snapshot(db: Session, product: models.Product) -> dict:
"description": snapshot.description,
"carateristique": carateristique,
"details": details,
"categorie_amazon": snapshot.categorie_amazon,
"dernier_scrape": snapshot.scrape_le,
"statut_scrap": snapshot.statut_scrap,
}