feat: Implement improved search service with supporting models, schemas, and API routers, and refactor site verification script.

This commit is contained in:
Michael committed 2025-11-30 23:33:05 +01:00
1 parent 4720ed6b93
commit 9855040f3e
21 files changed
+57932 -419

No files matched your search

+32 -11
View File
@@ -8,45 +8,66 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".")))
from app.services.search_service import new_search_service
from app.services.browserless_service import browserless_service
from app.core.search_config import SITE_CONFIGS
# Configure logging
logging.basicConfig(
level=logging.INFO,
level=logging.DEBUG, # Enable DEBUG logging
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[logging.StreamHandler()]
)
# Set other loggers to INFO to avoid noise
logging.getLogger("urllib3").setLevel(logging.INFO)
logging.getLogger("asyncio").setLevel(logging.INFO)
logging.getLogger("websockets").setLevel(logging.INFO)
async def verify_search():
query = "iphone 15"
query = "chaise" # Updated query
print(f"--- Starting Verification Search for '{query}' ---")
# 1. Test Browserless Connection
print("\n[1] Testing Browserless Connection...")
try:
await browserless_service.start()
await browserless_service.initialize()
print("✅ Browserless connected successfully")
except Exception as e:
print(f"❌ Browserless connection failed: {e}")
return
# 2. Test Specific Sites
sites_to_test = ["gifi.fr", "amazon.fr", "e.leclerc"]
# sites_to_test = ["gifi.fr", "lincroyable.fr", "stokomani.fr"] # Excluded amazon.fr
sites_to_test = ["stokomani.fr"] # Focus on Stokomani for now as requested/implied context
for site in sites_to_test:
print(f"\n[2] Testing Search on {site}...")
try:
results = await new_search_service.search_site(site, query)
if results:
print(f"✅ Found {len(results)} results for {site}")
for r in results[:2]:
print(f" - {r.title} ({r.url})")
else:
count = 0
async for r in new_search_service.search_site_generator(site, query):
count += 1
print(f"✅ Found result: {r.title} ({r.url})")
print(f" Price: {r.price} {r.currency}")
print(f" Image: {r.image_url}")
if count >= 1:
break
if count == 0:
print(f"⚠️ No results found for {site}")
# Dump HTML for debugging
try:
content, _ = await browserless_service.get_page_content(
SITE_CONFIGS[site]["search_url"].format(query=query),
use_proxy=SITE_CONFIGS[site].get("requires_proxy", False),
wait_selector=SITE_CONFIGS[site].get("wait_selector")
)
with open(f"/app/debug_dumps/{site}_failed_verification.html", "w", encoding="utf-8") as f:
f.write(content)
print(f"📄 Saved HTML dump to /app/debug_dumps/{site}_failed_verification.html")
except Exception as dump_e:
print(f"❌ Failed to save HTML dump: {dump_e}")
except Exception as e:
print(f"❌ Error searching {site}: {e}")
# 3. Cleanup
await browserless_service.stop()
await browserless_service.shutdown()
print("\n--- Verification Complete ---")
if __name__ == "__main__":