API endpoint parametreleri düzeltildi
Browse files
app.py
CHANGED
@@ -49,17 +49,26 @@ def normalize_turkish(text):
|
|
49 |
def get_realtime_stock(product_name):
|
50 |
"""API'den gerçek zamanlı stok bilgisini çek - Minimal versiyon"""
|
51 |
try:
|
52 |
-
# Önce mağaza listesini al
|
53 |
-
warehouses_url = f"{STOCK_API_BASE}?action=warehouses"
|
54 |
warehouses_response = requests.get(warehouses_url, timeout=5, verify=False)
|
55 |
|
56 |
if warehouses_response.status_code != 200:
|
|
|
57 |
return None
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Ürün adını normalize et
|
62 |
search_terms = normalize_turkish(product_name).lower().split()
|
|
|
63 |
|
64 |
# Her mağazanın stok bilgisini topla
|
65 |
stock_info = {}
|
@@ -69,14 +78,20 @@ def get_realtime_stock(product_name):
|
|
69 |
warehouse_id = warehouse['id']
|
70 |
warehouse_name = warehouse['title']
|
71 |
|
72 |
-
# Mağaza stoklarını al
|
73 |
-
inventory_url = f"{STOCK_API_BASE}?action=inventory&warehouse={warehouse_id}"
|
74 |
inventory_response = requests.get(inventory_url, timeout=5, verify=False)
|
75 |
|
76 |
if inventory_response.status_code != 200:
|
77 |
continue
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Ürünü ara
|
82 |
for product in products:
|
@@ -84,10 +99,14 @@ def get_realtime_stock(product_name):
|
|
84 |
|
85 |
# Tüm arama terimlerinin ürün başlığında olup olmadığını kontrol et
|
86 |
if all(term in product_title for term in search_terms):
|
|
|
|
|
87 |
stock = int(product.get('stock', 0))
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
break
|
92 |
|
93 |
if not stock_info:
|
|
|
49 |
def get_realtime_stock(product_name):
|
50 |
"""API'den gerçek zamanlı stok bilgisini çek - Minimal versiyon"""
|
51 |
try:
|
52 |
+
# Önce mağaza listesini al - endpoint parametresi eklendi
|
53 |
+
warehouses_url = f"{STOCK_API_BASE}?action=warehouses&endpoint=warehouses"
|
54 |
warehouses_response = requests.get(warehouses_url, timeout=5, verify=False)
|
55 |
|
56 |
if warehouses_response.status_code != 200:
|
57 |
+
print(f"Mağaza listesi alınamadı: {warehouses_response.status_code}")
|
58 |
return None
|
59 |
|
60 |
+
warehouses_data = warehouses_response.json()
|
61 |
+
|
62 |
+
# API yanıtını kontrol et
|
63 |
+
if 'data' in warehouses_data and 'warehouses' in warehouses_data['data']:
|
64 |
+
warehouses = warehouses_data['data']['warehouses']
|
65 |
+
else:
|
66 |
+
print("Mağaza verisi bulunamadı")
|
67 |
+
return None
|
68 |
|
69 |
# Ürün adını normalize et
|
70 |
search_terms = normalize_turkish(product_name).lower().split()
|
71 |
+
print(f"Aranan ürün: {product_name} -> {search_terms}")
|
72 |
|
73 |
# Her mağazanın stok bilgisini topla
|
74 |
stock_info = {}
|
|
|
78 |
warehouse_id = warehouse['id']
|
79 |
warehouse_name = warehouse['title']
|
80 |
|
81 |
+
# Mağaza stoklarını al - endpoint parametresi eklendi
|
82 |
+
inventory_url = f"{STOCK_API_BASE}?action=inventory&warehouse={warehouse_id}&endpoint=inventory/{warehouse_id}"
|
83 |
inventory_response = requests.get(inventory_url, timeout=5, verify=False)
|
84 |
|
85 |
if inventory_response.status_code != 200:
|
86 |
continue
|
87 |
|
88 |
+
inventory_data = inventory_response.json()
|
89 |
+
|
90 |
+
# API yanıtını kontrol et
|
91 |
+
if 'data' in inventory_data and 'inventory' in inventory_data['data']:
|
92 |
+
products = inventory_data['data']['inventory']
|
93 |
+
else:
|
94 |
+
continue
|
95 |
|
96 |
# Ürünü ara
|
97 |
for product in products:
|
|
|
99 |
|
100 |
# Tüm arama terimlerinin ürün başlığında olup olmadığını kontrol et
|
101 |
if all(term in product_title for term in search_terms):
|
102 |
+
# qty ve stock değerlerini kontrol et
|
103 |
+
qty = int(product.get('qty', 0))
|
104 |
stock = int(product.get('stock', 0))
|
105 |
+
actual_stock = max(qty, stock) # İkisinden büyük olanı al
|
106 |
+
|
107 |
+
if actual_stock > 0:
|
108 |
+
stock_info[warehouse_name] = actual_stock
|
109 |
+
total_stock += actual_stock
|
110 |
break
|
111 |
|
112 |
if not stock_info:
|