File size: 2,846 Bytes
40daea5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#!/usr/bin/env python3
"""Test actual get_product_price_and_link function"""
from smart_warehouse_with_price import get_product_price_and_link
# Test with debug prints
def test_with_debug():
print("Testing get_product_price_and_link('Marlin 5')...")
# Temporarily modify the function to add debug
import smart_warehouse_with_price
import xml.etree.ElementTree as ET
import re
# Get the XML
xml_content = smart_warehouse_with_price.get_cached_trek_xml()
if not xml_content:
print("No XML content")
return
root = ET.fromstring(xml_content)
search_name = "marlin 5"
clean_search = re.sub(r'\s*\(\d{4}\)\s*', '', search_name).strip()
print(f"Clean search: '{clean_search}'")
best_match = None
best_score = 0
best_name = None
count = 0
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()
# Turkish char normalization
tr_map = {'ı': 'i', 'ğ': 'g', 'ü': 'u', 'ş': 's', 'ö': 'o', 'ç': 'c'}
for tr, en in tr_map.items():
item_name = item_name.replace(tr, en)
clean_item = re.sub(r'\s*\(\d{4}\)\s*', '', item_name).strip()
score = 0
# Exact match
if clean_search == clean_item:
score += 100
elif clean_item.startswith(clean_search + " ") or clean_item == clean_search:
score += 50
else:
name_parts = clean_search.split()
for part in name_parts:
if part in clean_item:
score += 1
if score > 0:
count += 1
if count <= 10: # Show first 10 matches
print(f" {count}. {rootlabel_elem.text[:50]}: score={score}")
if score > best_score:
best_score = score
best_match = item
best_name = rootlabel_elem.text
print(f" >>> NEW BEST: {best_name} with score {best_score}")
print(f"\nFinal best match: {best_name}")
print(f"Best score: {best_score}")
if best_match is not None:
price_elem = best_match.find('priceTaxWithCur')
link_elem = best_match.find('productLink')
if price_elem is not None:
print(f"Price: {price_elem.text}")
if link_elem is not None:
print(f"Link: {link_elem.text}")
# Now test actual function
print("\n" + "="*60)
print("Actual function result:")
price, link = get_product_price_and_link("Marlin 5")
print(f"Price: {price}")
print(f"Link: {link}")
if __name__ == "__main__":
test_with_debug() |