Upload app.py
Browse files
app.py
CHANGED
@@ -62,6 +62,7 @@ else:
|
|
62 |
def get_warehouse_stock(product_name):
|
63 |
"""B2B API'den mağaza stok bilgilerini çek"""
|
64 |
try:
|
|
|
65 |
warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml.php'
|
66 |
response = requests.get(warehouse_url, verify=False, timeout=15)
|
67 |
|
@@ -96,14 +97,26 @@ def get_warehouse_stock(product_name):
|
|
96 |
normalized_search = normalize_turkish(search_name.replace('(2026)', '').replace('(2025)', '').replace(' - ', ' ').strip())
|
97 |
normalized_xml = normalize_turkish(xml_product_name.replace('(2026)', '').replace('(2025)', '').replace(' - ', ' ').strip())
|
98 |
|
99 |
-
# Extract
|
100 |
-
|
101 |
-
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
warehouses = product.find('Warehouses')
|
108 |
if warehouses is not None:
|
109 |
warehouse_info = []
|
@@ -757,8 +770,13 @@ def process_whatsapp_message_with_memory(user_message, phone_number):
|
|
757 |
for product_name in product_names[:3]: # Max 3 products
|
758 |
# Clean up the product name
|
759 |
product_name = product_name.strip()
|
|
|
|
|
|
|
|
|
|
|
760 |
# Skip status indicators
|
761 |
-
if product_name in ['Stokta mevcut', 'Stokta yok', 'Fiyat:', 'Kampanya:', 'İndirim:']:
|
762 |
continue
|
763 |
|
764 |
print(f"DEBUG: Mağaza stogu kontrol ediliyor: {product_name}")
|
|
|
62 |
def get_warehouse_stock(product_name):
|
63 |
"""B2B API'den mağaza stok bilgilerini çek"""
|
64 |
try:
|
65 |
+
import re
|
66 |
warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml.php'
|
67 |
response = requests.get(warehouse_url, verify=False, timeout=15)
|
68 |
|
|
|
97 |
normalized_search = normalize_turkish(search_name.replace('(2026)', '').replace('(2025)', '').replace(' - ', ' ').strip())
|
98 |
normalized_xml = normalize_turkish(xml_product_name.replace('(2026)', '').replace('(2025)', '').replace(' - ', ' ').strip())
|
99 |
|
100 |
+
# Extract key product identifiers (first 2-3 meaningful words)
|
101 |
+
search_words = normalized_search.split()
|
102 |
+
xml_words = normalized_xml.split()
|
103 |
|
104 |
+
# Calculate similarity score based on common words
|
105 |
+
common_words = set(search_words) & set(xml_words)
|
106 |
+
|
107 |
+
# Check if we have enough common words (at least 2 key words match)
|
108 |
+
# OR if the first two words match (brand + model number usually)
|
109 |
+
search_key = ' '.join(search_words[:2]) if len(search_words) >= 2 else normalized_search
|
110 |
+
xml_key = ' '.join(xml_words[:2]) if len(xml_words) >= 2 else normalized_xml
|
111 |
+
|
112 |
+
# Match if:
|
113 |
+
# 1. First two words are the same (e.g., "marlin 6", "checkpoint sl")
|
114 |
+
# 2. OR we have at least 2 common words
|
115 |
+
# 3. OR one contains the other (for partial matches)
|
116 |
+
if (search_key == xml_key or
|
117 |
+
len(common_words) >= 2 or
|
118 |
+
search_key in normalized_xml or
|
119 |
+
xml_key in normalized_search):
|
120 |
warehouses = product.find('Warehouses')
|
121 |
if warehouses is not None:
|
122 |
warehouse_info = []
|
|
|
770 |
for product_name in product_names[:3]: # Max 3 products
|
771 |
# Clean up the product name
|
772 |
product_name = product_name.strip()
|
773 |
+
|
774 |
+
# Remove numbering like "1." "2." from the beginning
|
775 |
+
import re
|
776 |
+
product_name = re.sub(r'^\d+\.\s*', '', product_name)
|
777 |
+
|
778 |
# Skip status indicators
|
779 |
+
if product_name in ['Stokta mevcut', 'Stokta yok', 'Fiyat:', 'Kampanya:', 'İndirim:', 'Birden fazla ürün buldum:']:
|
780 |
continue
|
781 |
|
782 |
print(f"DEBUG: Mağaza stogu kontrol ediliyor: {product_name}")
|