ghstedpixel commited on
Commit
1cd48db
·
verified ·
1 Parent(s): b71dca0

Update shopping.py

Browse files
Files changed (1) hide show
  1. shopping.py +10 -16
shopping.py CHANGED
@@ -49,13 +49,13 @@ async def fetch_serpapi_shopping(product_name: str, desired_size: str, client: h
49
  price_val = item.get("extracted_price")
50
  raw_link = item.get("merchant_link") or item.get("link") or item.get("product_link") or ""
51
 
52
- # Multi-Pass Deep Unwrapper Loop
53
  if "google.com" in raw_link:
54
  try:
55
  for _ in range(3):
56
  parsed_query = urllib.parse.parse_qs(urllib.parse.urlparse(raw_link).query)
57
  found_nested = False
58
- for param_key in ["q", "url", "adurl", "u", "link"]:
59
  if param_key in parsed_query:
60
  candidate = parsed_query[param_key][0]
61
  if "http" in candidate:
@@ -69,10 +69,6 @@ async def fetch_serpapi_shopping(product_name: str, desired_size: str, client: h
69
  except:
70
  pass
71
 
72
- # CRITICAL DIRECTIVITY GATE: Discard comparison page references entirely. No artificial search strings are forced.
73
- if "google.com" in raw_link:
74
- continue
75
-
76
  link = clean_google_link(raw_link)
77
  detected_size = desired_size if desired_size else (extract_universal_sizing(title) or "Standard")
78
  rating = item.get("rating")
@@ -213,16 +209,19 @@ async def scan_prices(product_name: str, desired_size: str = "", mode: str = "ba
213
  limits = httpx.Limits(max_keepalive_connections=5, max_connections=10)
214
 
215
  async with httpx.AsyncClient(limits=limits, http2=False, trust_env=False) as client:
 
216
  deals, scraped_pages = await asyncio.gather(
217
  fetch_serpapi_shopping(product_name, desired_size, client, mode=mode),
218
  get_tavily_payload(product_name, desired_size, client, mode=mode)
219
  )
220
 
221
- if not deals and not scraped_pages:
222
- print("🦆 [Engine Cascader] Primary routes cold. Deploying free scrape clusters...")
223
- scraped_pages = await fetch_ddg_backup_shopping(product_name, desired_size, client, mode=mode)
 
224
 
225
  results = []
 
226
  if scraped_pages:
227
  mode_constraint = ""
228
  if mode == "exact":
@@ -287,8 +286,8 @@ async def scan_prices(product_name: str, desired_size: str = "", mode: str = "ba
287
  "size": desired_size or "Standard"
288
  })
289
 
290
- # --- BLENDING AND DYNAMIC STREAM SELECTION ---
291
- # Collect verified deep store elements first, explicitly bypassing any residual google wrappers
292
  vetted_safe_deals = []
293
  for d in deals:
294
  if "google.com" not in d.get("url", ""):
@@ -298,11 +297,6 @@ async def scan_prices(product_name: str, desired_size: str = "", mode: str = "ba
298
  if not any(v['url'] == r['url'] for v in vetted_safe_deals):
299
  if r.get("url") and "google.com" not in r["url"]:
300
  vetted_safe_deals.append(r)
301
-
302
- if len(vetted_safe_deals) < 3:
303
- for d in deals:
304
- if d not in vetted_safe_deals and "google.com" not in d.get("url", ""):
305
- vetted_safe_deals.append(d)
306
 
307
  if not vetted_safe_deals: return []
308
 
 
49
  price_val = item.get("extracted_price")
50
  raw_link = item.get("merchant_link") or item.get("link") or item.get("product_link") or ""
51
 
52
+ # Multi-Pass Unwrapper Machine
53
  if "google.com" in raw_link:
54
  try:
55
  for _ in range(3):
56
  parsed_query = urllib.parse.parse_qs(urllib.parse.urlparse(raw_link).query)
57
  found_nested = False
58
+ for param_key in ["q", "url", "adurl", "u", "link", "destination"]:
59
  if param_key in parsed_query:
60
  candidate = parsed_query[param_key][0]
61
  if "http" in candidate:
 
69
  except:
70
  pass
71
 
 
 
 
 
72
  link = clean_google_link(raw_link)
73
  detected_size = desired_size if desired_size else (extract_universal_sizing(title) or "Standard")
74
  rating = item.get("rating")
 
209
  limits = httpx.Limits(max_keepalive_connections=5, max_connections=10)
210
 
211
  async with httpx.AsyncClient(limits=limits, http2=False, trust_env=False) as client:
212
+ # STEP 1: Always harvest primary and unstructured streams simultaneously
213
  deals, scraped_pages = await asyncio.gather(
214
  fetch_serpapi_shopping(product_name, desired_size, client, mode=mode),
215
  get_tavily_payload(product_name, desired_size, client, mode=mode)
216
  )
217
 
218
+ # STEP 2: Always deploy DuckDuckGo crawler nodes to stack the backup pool with deep paths
219
+ ddg_pages = await fetch_ddg_backup_shopping(product_name, desired_size, client, mode=mode)
220
+ if ddg_pages:
221
+ scraped_pages.extend(ddg_pages)
222
 
223
  results = []
224
+ # REMOVED THE BLOCKING 'and not deals' BUG. We now parse web blocks EVERY SINGLE TIME.
225
  if scraped_pages:
226
  mode_constraint = ""
227
  if mode == "exact":
 
286
  "size": desired_size or "Standard"
287
  })
288
 
289
+ # --- INTELLIGENT DIRECT-LINK STREAM BLENDER ---
290
+ # Pick up direct web retailer paths first, avoiding unresolvable google matrices entirely
291
  vetted_safe_deals = []
292
  for d in deals:
293
  if "google.com" not in d.get("url", ""):
 
297
  if not any(v['url'] == r['url'] for v in vetted_safe_deals):
298
  if r.get("url") and "google.com" not in r["url"]:
299
  vetted_safe_deals.append(r)
 
 
 
 
 
300
 
301
  if not vetted_safe_deals: return []
302