before claude

This commit is contained in:
Gilles Soulier
2026-01-18 06:26:17 +01:00
parent dc19315e5d
commit 740c3d7516
60 changed files with 3815 additions and 354 deletions

View File

@@ -13,7 +13,14 @@ from sqlalchemy.orm import Session
from pricewatch.app.core.logging import get_logger
from pricewatch.app.core.schema import ProductSnapshot
from pricewatch.app.db.models import PriceHistory, Product, ProductImage, ProductSpec, ScrapingLog
from pricewatch.app.db.models import (
ClassificationRule,
PriceHistory,
Product,
ProductImage,
ProductSpec,
ScrapingLog,
)
logger = get_logger("db.repository")
@@ -49,12 +56,58 @@ class ProductRepository:
product.title = snapshot.title
if snapshot.category:
product.category = snapshot.category
if snapshot.type:
product.type = snapshot.type
if snapshot.description:
product.description = snapshot.description
if snapshot.currency:
product.currency = snapshot.currency
if snapshot.msrp is not None:
product.msrp = snapshot.msrp
if snapshot.rating_value is not None:
product.rating_value = snapshot.rating_value
if snapshot.rating_count is not None:
product.rating_count = snapshot.rating_count
if snapshot.amazon_choice is not None:
product.amazon_choice = snapshot.amazon_choice
if snapshot.amazon_choice_label:
product.amazon_choice_label = snapshot.amazon_choice_label
if snapshot.discount_text:
product.discount_text = snapshot.discount_text
if snapshot.stock_text:
product.stock_text = snapshot.stock_text
if snapshot.in_stock is not None:
product.in_stock = snapshot.in_stock
if snapshot.model_number:
product.model_number = snapshot.model_number
if snapshot.model_name:
product.model_name = snapshot.model_name
def apply_classification(self, snapshot: ProductSnapshot) -> None:
"""Applique les regles de classification au snapshot."""
if not snapshot.title:
return
rules = (
self.session.query(ClassificationRule)
.filter(ClassificationRule.is_active == True)
.order_by(ClassificationRule.sort_order, ClassificationRule.id)
.all()
)
if not rules:
return
title = snapshot.title.lower()
for rule in rules:
keywords = rule.keywords or []
if isinstance(keywords, str):
keywords = [keywords]
if any(keyword and keyword.lower() in title for keyword in keywords):
if rule.category:
snapshot.category = rule.category
if rule.type:
snapshot.type = rule.type
return
def add_price_history(self, product: Product, snapshot: ProductSnapshot) -> Optional[PriceHistory]:
"""Ajoute une entree d'historique de prix si inexistante."""