#!/usr/bin/env python3 """ Test the specific Amazon short link provided by the user """ import asyncio import sys import os # Add the current directory to Python path to import our modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) from url_utils import expand_ecommerce_url, is_amazon_short_link from scraper import scrape import re from regex_patterns import amazon_url_patterns async def test_user_link(): """Test the specific user-provided Amazon short link""" user_link = "https://amzn.to/4nDPQmT" print(f"🔗 Testing user's Amazon short link: {user_link}") print("=" * 60) # Step 1: Check if it's a short link if is_amazon_short_link(user_link): print("✅ Detected as Amazon short link") # Step 2: Expand the URL print("🔄 Expanding URL...") expanded_url = expand_ecommerce_url(user_link) print(f"✅ Expanded URL: {expanded_url}") # Step 3: Verify it matches Amazon patterns platform = "amazon" if any(re.match(pattern, expanded_url) for pattern in amazon_url_patterns) else "unknown" print(f"🏷️ Detected platform: {platform}") if platform == "amazon": # Step 4: Try to scrape the product print("🔍 Attempting to scrape product information...") try: product_name, price = await scrape(expanded_url, platform) if product_name and price: print("🎉 SUCCESS! Product information extracted:") print(f" 📦 Product: {product_name}") print(f" 💰 Price: ₹{price}") else: print("❌ Failed to extract product information") except Exception as e: print(f"❌ Error during scraping: {e}") else: print("❌ URL doesn't match Amazon patterns after expansion") else: print("❌ Not detected as Amazon short link") if __name__ == "__main__": asyncio.run(test_user_link())