Genel stok arama algoritması - spesifik ürün adı yok
Browse files- Tüm ürünleri tara, eşleşeni bul
- Dinamik pattern matching
- Her ürün için çalışır, sadece Madone değil
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
app.py
CHANGED
@@ -29,9 +29,9 @@ from enhanced_features import (
|
|
29 |
)
|
30 |
from image_renderer import extract_product_info_for_gallery, format_message_with_images
|
31 |
|
32 |
-
#
|
33 |
def get_warehouse_stock(product_name):
|
34 |
-
"""
|
35 |
try:
|
36 |
import re
|
37 |
import requests
|
@@ -58,59 +58,75 @@ def get_warehouse_stock(product_name):
|
|
58 |
size = next((w for w in words if w in sizes), None)
|
59 |
product_words = [w for w in words if w not in sizes and w not in ['beden', 'size', 'boy']]
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
|
69 |
-
|
|
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
#
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
if
|
81 |
-
product_block = match.group(0)
|
82 |
-
|
83 |
-
# Extract warehouses
|
84 |
-
warehouse_info = []
|
85 |
-
warehouse_regex = r'<Warehouse>.*?<Name><!\[CDATA\[(.*?)\]\]></Name>.*?<Stock>(.*?)</Stock>.*?</Warehouse>'
|
86 |
-
warehouses = re.findall(warehouse_regex, product_block, re.DOTALL)
|
87 |
-
|
88 |
-
for wh_name, wh_stock in warehouses:
|
89 |
-
try:
|
90 |
-
stock = int(wh_stock.strip())
|
91 |
-
if stock > 0:
|
92 |
-
# Format name
|
93 |
-
if "CADDEBOSTAN" in wh_name:
|
94 |
-
display = "Caddebostan mağazası"
|
95 |
-
elif "ORTAKÖY" in wh_name:
|
96 |
-
display = "Ortaköy mağazası"
|
97 |
-
elif "ALSANCAK" in wh_name:
|
98 |
-
display = "İzmir Alsancak mağazası"
|
99 |
-
elif "BAHCEKOY" in wh_name or "BAHÇEKÖY" in wh_name:
|
100 |
-
display = "Bahçeköy mağazası"
|
101 |
-
else:
|
102 |
-
display = wh_name
|
103 |
-
|
104 |
-
warehouse_info.append(f"{display}: Mevcut")
|
105 |
-
except:
|
106 |
-
pass
|
107 |
-
|
108 |
-
return warehouse_info if warehouse_info else ["Hiçbir mağazada mevcut değil"]
|
109 |
-
else:
|
110 |
-
return ["Hiçbir mağazada mevcut değil"]
|
111 |
else:
|
112 |
-
|
113 |
-
return
|
114 |
|
115 |
except Exception as e:
|
116 |
print(f"Warehouse error: {e}")
|
|
|
29 |
)
|
30 |
from image_renderer import extract_product_info_for_gallery, format_message_with_images
|
31 |
|
32 |
+
# SMART warehouse stock finder - general algorithm
|
33 |
def get_warehouse_stock(product_name):
|
34 |
+
"""Smart warehouse stock finder with general algorithm"""
|
35 |
try:
|
36 |
import re
|
37 |
import requests
|
|
|
58 |
size = next((w for w in words if w in sizes), None)
|
59 |
product_words = [w for w in words if w not in sizes and w not in ['beden', 'size', 'boy']]
|
60 |
|
61 |
+
print(f"DEBUG - Searching: {' '.join(product_words)}, Size: {size}")
|
62 |
+
|
63 |
+
# Find all Product blocks in XML
|
64 |
+
product_pattern = r'<Product>(.*?)</Product>'
|
65 |
+
all_products = re.findall(product_pattern, xml_text, re.DOTALL)
|
66 |
+
|
67 |
+
print(f"DEBUG - Total products in XML: {len(all_products)}")
|
68 |
|
69 |
+
# Search through products
|
70 |
+
best_match = None
|
71 |
|
72 |
+
for product_block in all_products:
|
73 |
+
# Extract product name
|
74 |
+
name_match = re.search(r'<ProductName><!\[CDATA\[(.*?)\]\]></ProductName>', product_block)
|
75 |
+
if not name_match:
|
76 |
+
continue
|
77 |
+
|
78 |
+
product_name_in_xml = name_match.group(1)
|
79 |
+
normalized_xml_name = normalize(product_name_in_xml)
|
80 |
|
81 |
+
# Check if all product words are in the name
|
82 |
+
if all(word in normalized_xml_name for word in product_words):
|
83 |
+
# Product name matches, now check variant if needed
|
84 |
+
|
85 |
+
if size:
|
86 |
+
# Check if variant matches the size
|
87 |
+
variant_match = re.search(r'<ProductVariant><!\[CDATA\[(.*?)\]\]></ProductVariant>', product_block)
|
88 |
+
if variant_match:
|
89 |
+
variant = variant_match.group(1)
|
90 |
+
# Check if variant starts with the size (e.g., "S-BEYAZ")
|
91 |
+
if variant.upper().startswith(f'{size.upper()}-'):
|
92 |
+
print(f"DEBUG - Found match: {product_name_in_xml} - {variant}")
|
93 |
+
best_match = product_block
|
94 |
+
break # Found exact match, stop searching
|
95 |
+
else:
|
96 |
+
# No size specified, take first match
|
97 |
+
best_match = product_block
|
98 |
+
break
|
99 |
+
|
100 |
+
if best_match:
|
101 |
+
# Extract warehouse info from the matched product
|
102 |
+
warehouse_info = []
|
103 |
+
warehouse_regex = r'<Warehouse>.*?<Name><!\[CDATA\[(.*?)\]\]></Name>.*?<Stock>(.*?)</Stock>.*?</Warehouse>'
|
104 |
+
warehouses = re.findall(warehouse_regex, best_match, re.DOTALL)
|
105 |
|
106 |
+
for wh_name, wh_stock in warehouses:
|
107 |
+
try:
|
108 |
+
stock = int(wh_stock.strip())
|
109 |
+
if stock > 0:
|
110 |
+
# Format store names
|
111 |
+
if "CADDEBOSTAN" in wh_name:
|
112 |
+
display = "Caddebostan mağazası"
|
113 |
+
elif "ORTAKÖY" in wh_name:
|
114 |
+
display = "Ortaköy mağazası"
|
115 |
+
elif "ALSANCAK" in wh_name:
|
116 |
+
display = "İzmir Alsancak mağazası"
|
117 |
+
elif "BAHCEKOY" in wh_name or "BAHÇEKÖY" in wh_name:
|
118 |
+
display = "Bahçeköy mağazası"
|
119 |
+
else:
|
120 |
+
display = wh_name
|
121 |
+
|
122 |
+
warehouse_info.append(f"{display}: Mevcut")
|
123 |
+
except:
|
124 |
+
pass
|
125 |
|
126 |
+
return warehouse_info if warehouse_info else ["Hiçbir mağazada mevcut değil"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
else:
|
128 |
+
print(f"DEBUG - No match found for {' '.join(product_words)}")
|
129 |
+
return ["Hiçbir mağazada mevcut değil"]
|
130 |
|
131 |
except Exception as e:
|
132 |
print(f"Warehouse error: {e}")
|