mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-11 17:29:14 +02:00
Merge pull request #107 from R0m1k3/antigravity
feat: Add new search service for multi-site product search and item d…
This commit is contained in:
2 files changed
+41
-19
No files matched your search
@@ -82,11 +82,9 @@ SITE_CONFIGS = {
|
||||
"name": "Action",
|
||||
"search_url": "https://www.action.com/fr-fr/search/?q={query}",
|
||||
"product_selector": "a.group[href^='/fr-fr/p/']",
|
||||
"search_url": "https://www.amazon.fr/s?k={query}",
|
||||
"product_selector": "div[data-asin]:not([data-asin='']) h2 a",
|
||||
"wait_selector": "[data-component-type='s-search-result']",
|
||||
"category": "E-commerce",
|
||||
"requires_proxy": True,
|
||||
"wait_selector": "a.group[href^='/fr-fr/p/']",
|
||||
"category": "Discount",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
"cdiscount.com": {
|
||||
"name": "Cdiscount",
|
||||
|
||||
@@ -356,15 +356,19 @@ def update_site(db: Session, site_id: int, site_data: dict[str, Any]) -> SearchS
|
||||
return site
|
||||
|
||||
def seed_default_sites(db: Session) -> int:
|
||||
"""Initialise la base de données avec les sites configurés"""
|
||||
"""Initialise ou met à jour la base de données avec les sites configurés"""
|
||||
updated_count = 0
|
||||
created_count = 0
|
||||
existing_domains = {site.domain.lower().replace("www.", "") for site in db.query(SearchSite).all()}
|
||||
|
||||
# Get all existing sites mapped by domain
|
||||
existing_sites = {
|
||||
site.domain.lower().replace("www.", ""): site
|
||||
for site in db.query(SearchSite).all()
|
||||
}
|
||||
|
||||
for domain, config in SITE_CONFIGS.items():
|
||||
clean_domain = domain.lower().replace("www.", "")
|
||||
if clean_domain in existing_domains:
|
||||
continue
|
||||
|
||||
|
||||
site_data = {
|
||||
"name": config.get("name", domain),
|
||||
"domain": domain,
|
||||
@@ -376,16 +380,36 @@ def seed_default_sites(db: Session) -> int:
|
||||
"is_active": True,
|
||||
}
|
||||
|
||||
try:
|
||||
site = SearchSite(**site_data)
|
||||
db.add(site)
|
||||
db.commit()
|
||||
created_count += 1
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
logger.error(f"Erreur création site {domain}: {e}")
|
||||
if clean_domain in existing_sites:
|
||||
# Update existing site
|
||||
site = existing_sites[clean_domain]
|
||||
changed = False
|
||||
for key, value in site_data.items():
|
||||
if getattr(site, key) != value:
|
||||
setattr(site, key, value)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
try:
|
||||
db.commit()
|
||||
updated_count += 1
|
||||
logger.info(f"Site mis à jour: {domain}")
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
logger.error(f"Erreur mise à jour site {domain}: {e}")
|
||||
else:
|
||||
# Create new site
|
||||
try:
|
||||
site = SearchSite(**site_data)
|
||||
db.add(site)
|
||||
db.commit()
|
||||
created_count += 1
|
||||
logger.info(f"Nouveau site créé: {domain}")
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
logger.error(f"Erreur création site {domain}: {e}")
|
||||
|
||||
return created_count
|
||||
return created_count + updated_count
|
||||
|
||||
def reset_sites_to_defaults(db: Session) -> int:
|
||||
"""Réinitialise tous les sites"""
|
||||
|
||||
Reference in new issue
Block a user