mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-11 17:29:14 +02:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
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 = "gifi.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())
|