#!/usr/bin/env python3 import requests import xml.etree.ElementTree as ET def search_marlin_products(): """B2B API'den MARLIN ürünlerini listele""" try: warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml.php' response = requests.get(warehouse_url, verify=False, timeout=15) if response.status_code != 200: return None root = ET.fromstring(response.content) # Turkish character normalization function turkish_map = {'ı': 'i', 'ğ': 'g', 'ü': 'u', 'ş': 's', 'ö': 'o', 'ç': 'c', 'İ': 'i', 'I': 'i'} def normalize_turkish(text): import unicodedata text = unicodedata.normalize('NFD', text) text = ''.join(char for char in text if unicodedata.category(char) != 'Mn') for tr_char, en_char in turkish_map.items(): text = text.replace(tr_char, en_char) return text marlin_products = [] # MARLIN içeren tüm ürünleri bul for product in root.findall('Product'): product_name_elem = product.find('ProductName') if product_name_elem is not None and product_name_elem.text: xml_product_name = product_name_elem.text.strip() normalized_xml = normalize_turkish(xml_product_name.lower()) if 'marlin' in normalized_xml: # Stok durumunu kontrol et has_stock = False stock_info = [] warehouses = product.find('Warehouses') if warehouses is not None: for warehouse in warehouses.findall('Warehouse'): name_elem = warehouse.find('Name') stock_elem = warehouse.find('Stock') if name_elem is not None and stock_elem is not None: warehouse_name = name_elem.text if name_elem.text else "Bilinmeyen" try: stock_count = int(stock_elem.text) if stock_elem.text else 0 if stock_count > 0: stock_info.append(f"{warehouse_name}: {stock_count}") has_stock = True except (ValueError, TypeError): pass marlin_products.append({ 'name': xml_product_name, 'has_stock': has_stock, 'stock_info': stock_info }) return marlin_products except Exception as e: print(f"Arama hatası: {e}") return None def search_turuncu_products(): """B2B API'den TURUNCU içeren ürünleri listele""" try: warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml.php' response = requests.get(warehouse_url, verify=False, timeout=15) if response.status_code != 200: return None root = ET.fromstring(response.content) # Turkish character normalization function turkish_map = {'ı': 'i', 'ğ': 'g', 'ü': 'u', 'ş': 's', 'ö': 'o', 'ç': 'c', 'İ': 'i', 'I': 'i'} def normalize_turkish(text): import unicodedata text = unicodedata.normalize('NFD', text) text = ''.join(char for char in text if unicodedata.category(char) != 'Mn') for tr_char, en_char in turkish_map.items(): text = text.replace(tr_char, en_char) return text turuncu_products = [] # TURUNCU içeren tüm ürünleri bul for product in root.findall('Product'): product_name_elem = product.find('ProductName') if product_name_elem is not None and product_name_elem.text: xml_product_name = product_name_elem.text.strip() normalized_xml = normalize_turkish(xml_product_name.lower()) if 'turuncu' in normalized_xml: # Stok durumunu kontrol et has_stock = False stock_info = [] warehouses = product.find('Warehouses') if warehouses is not None: for warehouse in warehouses.findall('Warehouse'): name_elem = warehouse.find('Name') stock_elem = warehouse.find('Stock') if name_elem is not None and stock_elem is not None: warehouse_name = name_elem.text if name_elem.text else "Bilinmeyen" try: stock_count = int(stock_elem.text) if stock_elem.text else 0 if stock_count > 0: stock_info.append(f"{warehouse_name}: {stock_count}") has_stock = True except (ValueError, TypeError): pass turuncu_products.append({ 'name': xml_product_name, 'has_stock': has_stock, 'stock_info': stock_info }) return turuncu_products except Exception as e: print(f"Arama hatası: {e}") return None if __name__ == "__main__": print("=== MARLIN ÜRÜNLERİ ===") marlin_products = search_marlin_products() if marlin_products: print(f"Toplam {len(marlin_products)} MARLIN ürünü bulundu:") for i, product in enumerate(marlin_products, 1): print(f"{i:2}. {product['name']}") if product['has_stock']: print(f" STOKTA: {', '.join(product['stock_info'])}") else: print(f" STOKTA DEĞİL") print() print("\n" + "="*50) print("=== TURUNCU ÜRÜNLERİ ===") turuncu_products = search_turuncu_products() if turuncu_products: print(f"Toplam {len(turuncu_products)} TURUNCU ürünü bulundu:") for i, product in enumerate(turuncu_products, 1): print(f"{i:2}. {product['name']}") if product['has_stock']: print(f" STOKTA: {', '.join(product['stock_info'])}") else: print(f" STOKTA DEĞİL") print()