Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -28,7 +28,6 @@ from popular import get_trending_deals
|
|
| 28 |
|
| 29 |
app = FastAPI()
|
| 30 |
|
| 31 |
-
# Tell Jinja2 to look directly in the root directory where your files live
|
| 32 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 33 |
templates = Jinja2Templates(directory=BASE_DIR)
|
| 34 |
|
|
@@ -125,8 +124,7 @@ async def handle_search(
|
|
| 125 |
deals = []
|
| 126 |
coupons = []
|
| 127 |
original_site_deal = None
|
| 128 |
-
|
| 129 |
-
|
| 130 |
if target_item.startswith(("http://", "https://")):
|
| 131 |
input_url = target_item
|
| 132 |
print(f"🔗 [Input URL] Pasted hyperlink reference intercepted: {input_url}")
|
|
@@ -200,7 +198,6 @@ async def handle_search(
|
|
| 200 |
else:
|
| 201 |
print(f"❄️ [Cache Miss] Initiating parallel engine verification sequence for pricing & deals...")
|
| 202 |
|
| 203 |
-
# Parallel Engine Lookups
|
| 204 |
markdown_deals, product_offers = await asyncio.gather(
|
| 205 |
fetch_deals_standalone(target_item),
|
| 206 |
scan_prices(target_item, requested_size, search_mode)
|
|
@@ -215,7 +212,6 @@ async def handle_search(
|
|
| 215 |
market_max_price = max([x.get('price', 0) for x in product_offers if x.get('price', 0) > 0]) or 1.0
|
| 216 |
processed_percentage_badges = []
|
| 217 |
|
| 218 |
-
# --- START REAL-WORLD GOOGLE DISCOUNT & GRANULAR HISTORICAL ENGINE ---
|
| 219 |
for item in product_offers:
|
| 220 |
cur_p = item.get('price', 0)
|
| 221 |
if not cur_p:
|
|
@@ -272,7 +268,6 @@ async def handle_search(
|
|
| 272 |
"description": badge_string,
|
| 273 |
"source": item_source
|
| 274 |
})
|
| 275 |
-
# --- END REAL-WORLD GOOGLE DISCOUNT & GRANULAR HISTORICAL ENGINE ---
|
| 276 |
|
| 277 |
current_lowest = product_offers[0]['price']
|
| 278 |
base_price = get_base_price(target_item, requested_size, search_mode)
|
|
@@ -297,20 +292,20 @@ async def handle_search(
|
|
| 297 |
|
| 298 |
size_header = f" ({requested_size})" if requested_size else ""
|
| 299 |
|
|
|
|
| 300 |
for d in deals:
|
| 301 |
if "url" not in d and "link" in d:
|
| 302 |
d["url"] = d["link"]
|
| 303 |
elif "link" not in d and "url" in d:
|
| 304 |
d["link"] = d["url"]
|
| 305 |
|
| 306 |
-
# Recursive unwrapping check to catch any residual proxy tracking strings
|
| 307 |
current_url = d.get("url", "")
|
| 308 |
if current_url and "google.com" in current_url:
|
| 309 |
try:
|
| 310 |
for _ in range(3):
|
| 311 |
parsed_query = parse_qs(urlparse(current_url).query)
|
| 312 |
found_nested = False
|
| 313 |
-
for param_key in ["q", "url", "adurl", "u", "link", "destination"]:
|
| 314 |
if parsed_query.get(param_key):
|
| 315 |
candidate = parsed_query[param_key][0]
|
| 316 |
if "http" in candidate:
|
|
@@ -326,19 +321,22 @@ async def handle_search(
|
|
| 326 |
except:
|
| 327 |
pass
|
| 328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
try:
|
| 330 |
d["source_domain"] = d.get("source") or urlparse(d["url"]).netloc.replace("www.", "")
|
| 331 |
except:
|
| 332 |
d["source_domain"] = "retailer.link"
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
deals = [d for d in deals if "google.com" not in d.get("url", "")]
|
| 336 |
|
| 337 |
base_ui_context.update({
|
| 338 |
"show_results": True,
|
| 339 |
"target_item": target_item,
|
| 340 |
"size_header": size_header,
|
| 341 |
-
"deals":
|
| 342 |
"coupons": coupons,
|
| 343 |
"is_ref_url": original_site_deal["url"] if original_site_deal else None
|
| 344 |
})
|
|
|
|
| 28 |
|
| 29 |
app = FastAPI()
|
| 30 |
|
|
|
|
| 31 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 32 |
templates = Jinja2Templates(directory=BASE_DIR)
|
| 33 |
|
|
|
|
| 124 |
deals = []
|
| 125 |
coupons = []
|
| 126 |
original_site_deal = None
|
| 127 |
+
|
|
|
|
| 128 |
if target_item.startswith(("http://", "https://")):
|
| 129 |
input_url = target_item
|
| 130 |
print(f"🔗 [Input URL] Pasted hyperlink reference intercepted: {input_url}")
|
|
|
|
| 198 |
else:
|
| 199 |
print(f"❄️ [Cache Miss] Initiating parallel engine verification sequence for pricing & deals...")
|
| 200 |
|
|
|
|
| 201 |
markdown_deals, product_offers = await asyncio.gather(
|
| 202 |
fetch_deals_standalone(target_item),
|
| 203 |
scan_prices(target_item, requested_size, search_mode)
|
|
|
|
| 212 |
market_max_price = max([x.get('price', 0) for x in product_offers if x.get('price', 0) > 0]) or 1.0
|
| 213 |
processed_percentage_badges = []
|
| 214 |
|
|
|
|
| 215 |
for item in product_offers:
|
| 216 |
cur_p = item.get('price', 0)
|
| 217 |
if not cur_p:
|
|
|
|
| 268 |
"description": badge_string,
|
| 269 |
"source": item_source
|
| 270 |
})
|
|
|
|
| 271 |
|
| 272 |
current_lowest = product_offers[0]['price']
|
| 273 |
base_price = get_base_price(target_item, requested_size, search_mode)
|
|
|
|
| 292 |
|
| 293 |
size_header = f" ({requested_size})" if requested_size else ""
|
| 294 |
|
| 295 |
+
validated_deals = []
|
| 296 |
for d in deals:
|
| 297 |
if "url" not in d and "link" in d:
|
| 298 |
d["url"] = d["link"]
|
| 299 |
elif "link" not in d and "url" in d:
|
| 300 |
d["link"] = d["url"]
|
| 301 |
|
|
|
|
| 302 |
current_url = d.get("url", "")
|
| 303 |
if current_url and "google.com" in current_url:
|
| 304 |
try:
|
| 305 |
for _ in range(3):
|
| 306 |
parsed_query = parse_qs(urlparse(current_url).query)
|
| 307 |
found_nested = False
|
| 308 |
+
for param_key in ["q", "url", "adurl", "u", "link", "destination", "ad_url"]:
|
| 309 |
if parsed_query.get(param_key):
|
| 310 |
candidate = parsed_query[param_key][0]
|
| 311 |
if "http" in candidate:
|
|
|
|
| 321 |
except:
|
| 322 |
pass
|
| 323 |
|
| 324 |
+
# Protect dashboard interface from rendering layout overview frame pages
|
| 325 |
+
if "/shopping/product/" in current_url or "/shopping/landing" in current_url:
|
| 326 |
+
continue
|
| 327 |
+
|
| 328 |
try:
|
| 329 |
d["source_domain"] = d.get("source") or urlparse(d["url"]).netloc.replace("www.", "")
|
| 330 |
except:
|
| 331 |
d["source_domain"] = "retailer.link"
|
| 332 |
+
|
| 333 |
+
validated_deals.append(d)
|
|
|
|
| 334 |
|
| 335 |
base_ui_context.update({
|
| 336 |
"show_results": True,
|
| 337 |
"target_item": target_item,
|
| 338 |
"size_header": size_header,
|
| 339 |
+
"deals": validated_deals,
|
| 340 |
"coupons": coupons,
|
| 341 |
"is_ref_url": original_site_deal["url"] if original_site_deal else None
|
| 342 |
})
|