#!/usr/bin/env python3 """Debug why Marlin 5 returns Rail""" import requests import xml.etree.ElementTree as ET import re def debug_matching(): """See what matches when searching for Marlin 5""" # Get Trek XML url = 'https://www.trekbisiklet.com.tr/output/8582384479' response = requests.get(url, verify=False, timeout=10) if response.status_code != 200: print("Failed to fetch XML") return root = ET.fromstring(response.content) # Search parameters (from smart_warehouse_with_price.py logic) search_name = "marlin 5" clean_search = re.sub(r'\s*\(\d{4}\)\s*', '', search_name).strip() print(f"Searching for: '{search_name}'") print(f"Clean search: '{clean_search}'") print(f"Search parts: {clean_search.split()}") print("\n" + "="*60) matches = [] for item in root.findall('item'): rootlabel_elem = item.find('rootlabel') if rootlabel_elem is None or not rootlabel_elem.text: continue item_name = rootlabel_elem.text.lower() clean_item = re.sub(r'\s*\(\d{4}\)\s*', '', item_name).strip() # Calculate score (same logic as smart_warehouse_with_price.py) score = 0 # Exact match if clean_search == clean_item: score += 100 # Starts with elif clean_item.startswith(clean_search + " ") or clean_item == clean_search: score += 50 else: # Partial matching name_parts = clean_search.split() for part in name_parts: if part in clean_item: score += 1 if score > 0: price_elem = item.find('priceTaxWithCur') link_elem = item.find('productLink') matches.append({ 'original': rootlabel_elem.text, 'clean': clean_item, 'score': score, 'price': price_elem.text if price_elem is not None else 'N/A', 'link': link_elem.text if link_elem is not None else 'N/A' }) # Sort by score matches.sort(key=lambda x: x['score'], reverse=True) print(f"\nFound {len(matches)} matches:") print("="*60) for i, match in enumerate(matches[:20], 1): # Show top 20 print(f"\n{i}. Score: {match['score']}") print(f" Original: {match['original']}") print(f" Clean: {match['clean']}") print(f" Price: {match['price']}") if match['link'] != 'N/A': print(f" Link: ...{match['link'][-50:]}") # Explain why it matched print(" Why matched:") if clean_search == match['clean']: print(" - EXACT MATCH") elif match['clean'].startswith(clean_search + " "): print(" - STARTS WITH search") else: parts = clean_search.split() for part in parts: if part in match['clean']: print(f" - Contains '{part}'") if __name__ == "__main__": debug_matching()