mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-23 07:08:12 +02:00
Merge pull request #202 from R0m1k3/antigravity
feat: Add improved search service with persistent browser connection …
This commit is contained in:
2 files changed
+25
-22
No files matched your search
@@ -1,6 +1,21 @@
|
|||||||
"""
|
"""
|
||||||
Improved Search Service - Using Persistent Browser Connection
|
Improved Search Service - Using Persistent Browser Connection
|
||||||
from app.services.parsers import ParserFactory, ProductResult
|
Based on ScraperService pattern for better session management and reliability
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
from typing import AsyncGenerator, Optional
|
||||||
|
from urllib.parse import quote_plus, urljoin, urlparse
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from playwright.async_api import Browser, BrowserContext, Page, async_playwright
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.core.search_config import SITE_CONFIGS, BROWSERLESS_URL
|
||||||
|
from app.services.ai_price_extractor import AIPriceExtractor
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -51,25 +51,13 @@ export default function Search() {
|
|||||||
|
|
||||||
// Charger les sites au démarrage
|
// Charger les sites au démarrage
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadSites();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const loadSites = async () => {
|
|
||||||
try {
|
|
||||||
const response = await axios.get(`${API_URL}/search-sites`);
|
|
||||||
const activeSites = response.data.filter(site => site.is_active);
|
|
||||||
setSites(activeSites);
|
|
||||||
// Sélectionner le premier site actif par défaut si aucun site n'est sélectionné
|
|
||||||
if (activeSites.length > 0 && !selectedSiteId) {
|
|
||||||
setSelectedSiteId(activeSites[0].id.toString());
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading sites:', error);
|
console.error('Error loading sites:', error);
|
||||||
toast.error('Erreur lors du chargement des sites');
|
toast.error('Erreur lors du chargement des sites');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSearch = async (e) => {
|
const handleSearch = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!query.trim() || !selectedSiteId) {
|
if (!query.trim() || !selectedSiteId) {
|
||||||
toast.error('Veuillez entrer une recherche et sélectionner un site');
|
toast.error('Veuillez entrer une recherche et sélectionner un site');
|
||||||
@@ -125,9 +113,9 @@ export default function Search() {
|
|||||||
eventSource.close();
|
eventSource.close();
|
||||||
toast.error('Erreur de connexion au serveur');
|
toast.error('Erreur de connexion au serveur');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddToMonitoring = async (result) => {
|
const handleAddToMonitoring = async (result) => {
|
||||||
try {
|
try {
|
||||||
await axios.post(`${API_URL}/items`, {
|
await axios.post(`${API_URL}/items`, {
|
||||||
url: result.url,
|
url: result.url,
|
||||||
@@ -140,15 +128,15 @@ export default function Search() {
|
|||||||
console.error('Error adding item:', error);
|
console.error('Error adding item:', error);
|
||||||
toast.error("Erreur lors de l'ajout au monitoring");
|
toast.error("Erreur lors de l'ajout au monitoring");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const progressPercent = progress
|
const progressPercent = progress
|
||||||
? Math.round((progress.completed / Math.max(progress.total, 1)) * 100)
|
? Math.round((progress.completed / Math.max(progress.total, 1)) * 100)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const selectedSite = sites.find(s => s.id.toString() === selectedSiteId);
|
const selectedSite = sites.find(s => s.id.toString() === selectedSiteId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 animate-in fade-in duration-500">
|
<div className="space-y-6 animate-in fade-in duration-500">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
||||||
@@ -282,5 +270,5 @@ export default function Search() {
|
|||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user