|
"""Ultra simple and fast warehouse stock finder""" |
|
|
|
def get_warehouse_stock(product_name): |
|
"""Find warehouse stock FAST - no XML parsing, just regex""" |
|
try: |
|
import re |
|
import requests |
|
|
|
|
|
url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml-b2b-api-v2.php' |
|
response = requests.get(url, verify=False, timeout=7) |
|
xml_text = response.text |
|
|
|
|
|
def normalize(text): |
|
tr_map = {'ı': 'i', 'ğ': 'g', 'ü': 'u', 'ş': 's', 'ö': 'o', 'ç': 'c', 'İ': 'i', 'I': 'i'} |
|
text = text.lower() |
|
for tr, en in tr_map.items(): |
|
text = text.replace(tr, en) |
|
return text |
|
|
|
|
|
query = normalize(product_name.strip()).replace('(2026)', '').replace('(2025)', '').strip() |
|
words = query.split() |
|
|
|
|
|
sizes = ['s', 'm', 'l', 'xl', 'xs', 'xxl', 'ml'] |
|
size = next((w for w in words if w in sizes), None) |
|
product_words = [w for w in words if w not in sizes and w not in ['beden', 'size', 'boy']] |
|
|
|
|
|
if 'madone' in product_words and 'sl' in product_words and '6' in product_words: |
|
pattern = 'MADONE SL 6 GEN 8' |
|
else: |
|
pattern = ' '.join(product_words).upper() |
|
|
|
print(f"DEBUG - Searching: {pattern}, Size: {size}") |
|
|
|
|
|
if size: |
|
|
|
size_pattern = f'{size.upper()}-' |
|
|
|
|
|
import re |
|
product_regex = f'<Product>.*?<ProductName><!\\[CDATA\\[{re.escape(pattern)}\\]\\]></ProductName>.*?<ProductVariant><!\\[CDATA\\[{size_pattern}.*?\\]\\]></ProductVariant>.*?</Product>' |
|
|
|
match = re.search(product_regex, xml_text, re.DOTALL) |
|
|
|
if match: |
|
product_block = match.group(0) |
|
print(f"DEBUG - Found product with {size_pattern} variant") |
|
|
|
|
|
warehouse_info = [] |
|
warehouse_regex = r'<Warehouse>.*?<Name><!\\[CDATA\\[(.*?)\\]\\]></Name>.*?<Stock>(.*?)</Stock>.*?</Warehouse>' |
|
warehouses = re.findall(warehouse_regex, product_block, re.DOTALL) |
|
|
|
for wh_name, wh_stock in warehouses: |
|
try: |
|
stock = int(wh_stock.strip()) |
|
if stock > 0: |
|
|
|
if "CADDEBOSTAN" in wh_name: |
|
display = "Caddebostan mağazası" |
|
elif "ORTAKÖY" in wh_name: |
|
display = "Ortaköy mağazası" |
|
elif "ALSANCAK" in wh_name: |
|
display = "İzmir Alsancak mağazası" |
|
elif "BAHCEKOY" in wh_name or "BAHÇEKÖY" in wh_name: |
|
display = "Bahçeköy mağazası" |
|
else: |
|
display = wh_name |
|
|
|
warehouse_info.append(f"{display}: Mevcut") |
|
except: |
|
pass |
|
|
|
return warehouse_info if warehouse_info else ["Hiçbir mağazada mevcut değil"] |
|
else: |
|
print(f"DEBUG - No {size_pattern} variant found for {pattern}") |
|
return ["Hiçbir mağazada mevcut değil"] |
|
else: |
|
|
|
return ["Beden bilgisi belirtilmedi"] |
|
|
|
except Exception as e: |
|
print(f"Error: {e}") |
|
return None |