From 0ff229de13f2bd5aa213e8741fbbe82027946273 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Mon, 22 Dec 2025 15:24:09 +0100 Subject: [PATCH] feat: add price verification script and update task.md to investigate comparator price extraction issues. --- task.md | 9 +++++++-- verify_search_price.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 verify_search_price.py diff --git a/task.md b/task.md index 523f804..52b5469 100644 --- a/task.md +++ b/task.md @@ -2,9 +2,8 @@ ## 🚀 Current Focus +- [ ] Investigate Comparator Price Extraction (User reported false prices) - [x] Fix Catalog Images (Generic/Missing icons) -- [x] Address "PDF vs Image" question -- [x] Implement "Delete Images" (Cleanup bad data) ## 📋 Master Plan @@ -27,6 +26,11 @@ - [x] **Cleanup Bad Data**: - [x] Run cleanup endpoint. - [x] Verify fix with new scrape. +- [/] **Comparator Price Fix**: + - [ ] Reproduce "False Price" issue with script. + - [ ] Audit `improved_search_service.py` extraction logic (Lowest Price vs AI). + - [ ] Implement robust price validation/filtering. + - [ ] Verify fix. ## 📝 Progress Log @@ -34,3 +38,4 @@ - **2025-12-22**: Fixed Catalog Retrieval using HTTP fallback. - **2025-12-22**: Investigating generic icon issue. Found images are served via Thumbor. - **2025-12-22**: **FIXED**: Scraper now targets Thumbor images. Wiped bad catalogs. +- **2025-12-22**: User reported incorrect prices in Comparator. Investigating. diff --git a/verify_search_price.py b/verify_search_price.py new file mode 100644 index 0000000..433821a --- /dev/null +++ b/verify_search_price.py @@ -0,0 +1,45 @@ +import asyncio +import logging +import sys +import os + +# Identify workspace root +sys.path.append(os.getcwd()) + +# Mock Env Vars +os.environ["DATABASE_URL"] = "postgresql://user:password@localhost:5432/pricewatch" +os.environ["BROWSERLESS_URL"] = "ws://localhost:3012" # Ignored by patch, but good for completeness + +from app.services.improved_search_service import ImprovedSearchService +from playwright.async_api import async_playwright + +# Setup logging +logging.basicConfig(level=logging.DEBUG) # DEBUG level to see price extraction logic +logger = logging.getLogger(__name__) + + +# Monkey patch _connect_browser to use local launch +async def _connect_browser_local(p): + logger.info("Launching local browser (headless)...") + return await p.chromium.launch(headless=True) + + +ImprovedSearchService._connect_browser = _connect_browser_local + + +async def test_search(): + await ImprovedSearchService.initialize() + + query = "nintendo switch" + target_site = "stokomani.fr" + + print(f"Searching for: {query} on {target_site}") + + async for result in ImprovedSearchService.search_site_generator(target_site, query): + print(f"[{result.source}] {result.title}\n -> Price: {result.price}€\n -> URL: {result.url}") + + await ImprovedSearchService.shutdown() + + +if __name__ == "__main__": + asyncio.run(test_search())