Update app.py
Browse files
app.py
CHANGED
@@ -48,130 +48,135 @@ if root is not None:
|
|
48 |
name_words = item.find('rootlabel').text.lower().split()
|
49 |
name = name_words[0]
|
50 |
full_name = ' '.join(name_words)
|
51 |
-
|
52 |
-
stock_amount = "stokta" if item.find('stockAmount').text > '0' else "stokta değil"
|
53 |
-
|
54 |
-
# Stokta olmayan ürünler için fiyat/link bilgisi eklemiyoruz
|
55 |
-
if stock_amount == "stokta":
|
56 |
-
# Normal fiyat bilgisini al
|
57 |
-
price_str = item.find('priceTaxWithCur').text if item.find('priceTaxWithCur') is not None else "Fiyat bilgisi yok"
|
58 |
-
|
59 |
-
# EFT fiyatını al (havale indirimli orijinal fiyat)
|
60 |
-
price_eft_str = item.find('priceEft').text if item.find('priceEft') is not None else ""
|
61 |
|
62 |
-
|
63 |
-
price_rebate_str = item.find('priceRebateWithTax').text if item.find('priceRebateWithTax') is not None else ""
|
64 |
-
|
65 |
-
# Havale indirimi fiyatını al (havale indirimli kampanyalı fiyat)
|
66 |
-
price_rebate_money_order_str = item.find('priceRebateWithMoneyOrderWithTax').text if item.find('priceRebateWithMoneyOrderWithTax') is not None else ""
|
67 |
-
|
68 |
-
# Normal fiyatı yuvarla
|
69 |
-
try:
|
70 |
-
price_float = float(price_str)
|
71 |
-
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
72 |
-
if price_float > 200000:
|
73 |
-
price = str(round(price_float / 5000) * 5000) # En yakın 5000'e yuvarla
|
74 |
-
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
75 |
-
elif price_float > 30000:
|
76 |
-
price = str(round(price_float / 1000) * 1000) # En yakın 1000'e yuvarla
|
77 |
-
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
78 |
-
elif price_float > 10000:
|
79 |
-
price = str(round(price_float / 100) * 100) # En yakın 100'e yuvarla
|
80 |
-
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
81 |
-
else:
|
82 |
-
price = str(round(price_float / 10) * 10) # En yakın 10'a yuvarla
|
83 |
-
except (ValueError, TypeError):
|
84 |
-
price = price_str # Sayıya dönüştürülemezse olduğu gibi bırak
|
85 |
|
86 |
-
#
|
87 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
try:
|
89 |
-
|
90 |
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
91 |
-
if
|
92 |
-
|
93 |
-
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
94 |
-
elif
|
95 |
-
|
96 |
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
97 |
-
elif
|
98 |
-
|
99 |
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
100 |
else:
|
101 |
-
|
102 |
except (ValueError, TypeError):
|
103 |
-
|
104 |
-
|
105 |
-
# Havale indirimli
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
try:
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
118 |
else:
|
119 |
-
|
120 |
except (ValueError, TypeError):
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
else:
|
140 |
-
price_rebate = ""
|
141 |
-
except (ValueError, TypeError):
|
142 |
-
price_rebate = price_rebate_str
|
143 |
-
|
144 |
-
# Havale indirimi kampanyalı fiyatı yuvarla
|
145 |
-
try:
|
146 |
-
if price_rebate_money_order_str:
|
147 |
-
price_rebate_money_order_float = float(price_rebate_money_order_str)
|
148 |
-
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
149 |
-
if price_rebate_money_order_float > 200000:
|
150 |
-
price_rebate_money_order = str(round(price_rebate_money_order_float / 5000) * 5000)
|
151 |
-
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
152 |
-
elif price_rebate_money_order_float > 30000:
|
153 |
-
price_rebate_money_order = str(round(price_rebate_money_order_float / 1000) * 1000)
|
154 |
-
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
155 |
-
elif price_rebate_money_order_float > 10000:
|
156 |
-
price_rebate_money_order = str(round(price_rebate_money_order_float / 100) * 100)
|
157 |
-
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
158 |
else:
|
159 |
-
price_rebate_money_order =
|
160 |
-
|
161 |
-
price_rebate_money_order =
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
products.append((name, item_info, full_name))
|
175 |
|
176 |
# Hugging Face token
|
177 |
hfapi = os.getenv("hfapi")
|
@@ -332,8 +337,16 @@ def chatbot_fn(user_message, history):
|
|
332 |
|
333 |
# Kullanıcı mesajında ürün ismi geçiyorsa ekle
|
334 |
input_words = user_message.lower().split()
|
|
|
|
|
335 |
for product_info in products:
|
336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
if product_info[1][0] == "stokta":
|
338 |
# Kampanyalı fiyat kontrolü
|
339 |
has_campaign = product_info[1][4] and product_info[1][4] != ""
|
|
|
48 |
name_words = item.find('rootlabel').text.lower().split()
|
49 |
name = name_words[0]
|
50 |
full_name = ' '.join(name_words)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
stock_amount = "stokta" if item.find('stockAmount').text > '0' else "stokta değil"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
# Stokta olmayan ürünler için fiyat/link bilgisi eklemiyoruz
|
55 |
+
if stock_amount == "stokta":
|
56 |
+
# Normal fiyat bilgisini al
|
57 |
+
price_str = item.find('priceTaxWithCur').text if item.find('priceTaxWithCur') is not None else "Fiyat bilgisi yok"
|
58 |
+
|
59 |
+
# EFT fiyatını al (havale indirimli orijinal fiyat)
|
60 |
+
price_eft_str = item.find('priceEft').text if item.find('priceEft') is not None else ""
|
61 |
+
|
62 |
+
# İndirimli fiyatı al (kampanyalı fiyat)
|
63 |
+
price_rebate_str = item.find('priceRebateWithTax').text if item.find('priceRebateWithTax') is not None else ""
|
64 |
+
|
65 |
+
# Havale indirimi fiyatını al (havale indirimli kampanyalı fiyat)
|
66 |
+
price_rebate_money_order_str = item.find('priceRebateWithMoneyOrderWithTax').text if item.find('priceRebateWithMoneyOrderWithTax') is not None else ""
|
67 |
+
|
68 |
+
# Normal fiyatı yuvarla
|
69 |
try:
|
70 |
+
price_float = float(price_str)
|
71 |
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
72 |
+
if price_float > 200000:
|
73 |
+
price = str(round(price_float / 5000) * 5000) # En yakın 5000'e yuvarla
|
74 |
+
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
75 |
+
elif price_float > 30000:
|
76 |
+
price = str(round(price_float / 1000) * 1000) # En yakın 1000'e yuvarla
|
77 |
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
78 |
+
elif price_float > 10000:
|
79 |
+
price = str(round(price_float / 100) * 100) # En yakın 100'e yuvarla
|
80 |
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
81 |
else:
|
82 |
+
price = str(round(price_float / 10) * 10) # En yakın 10'a yuvarla
|
83 |
except (ValueError, TypeError):
|
84 |
+
price = price_str # Sayıya dönüştürülemezse olduğu gibi bırak
|
85 |
+
|
86 |
+
# Havale indirimli orijinal fiyatı yuvarla (varsa)
|
87 |
+
if price_eft_str:
|
88 |
+
try:
|
89 |
+
price_eft_float = float(price_eft_str)
|
90 |
+
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
91 |
+
if price_eft_float > 200000:
|
92 |
+
price_eft = str(round(price_eft_float / 5000) * 5000)
|
93 |
+
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
94 |
+
elif price_eft_float > 30000:
|
95 |
+
price_eft = str(round(price_eft_float / 1000) * 1000)
|
96 |
+
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
97 |
+
elif price_eft_float > 10000:
|
98 |
+
price_eft = str(round(price_eft_float / 100) * 100)
|
99 |
+
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
100 |
+
else:
|
101 |
+
price_eft = str(round(price_eft_float / 10) * 10)
|
102 |
+
except (ValueError, TypeError):
|
103 |
+
price_eft = price_eft_str
|
104 |
+
else:
|
105 |
+
# Havale indirimli fiyat verilmemişse, orijinal fiyattan %2.5 indirim hesapla
|
106 |
+
try:
|
107 |
+
price_eft_float = price_float * 0.975 # %2.5 indirim
|
108 |
+
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
109 |
+
if price_eft_float > 200000:
|
110 |
+
price_eft = str(round(price_eft_float / 5000) * 5000)
|
111 |
+
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
112 |
+
elif price_eft_float > 30000:
|
113 |
+
price_eft = str(round(price_eft_float / 1000) * 1000)
|
114 |
+
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
115 |
+
elif price_eft_float > 10000:
|
116 |
+
price_eft = str(round(price_eft_float / 100) * 100)
|
117 |
+
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
118 |
+
else:
|
119 |
+
price_eft = str(round(price_eft_float / 10) * 10)
|
120 |
+
except (ValueError, TypeError):
|
121 |
+
price_eft = ""
|
122 |
+
|
123 |
+
# İndirimli fiyatı yuvarla
|
124 |
try:
|
125 |
+
if price_rebate_str:
|
126 |
+
price_rebate_float = float(price_rebate_str)
|
127 |
+
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
128 |
+
if price_rebate_float > 200000:
|
129 |
+
price_rebate = str(round(price_rebate_float / 5000) * 5000)
|
130 |
+
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
131 |
+
elif price_rebate_float > 30000:
|
132 |
+
price_rebate = str(round(price_rebate_float / 1000) * 1000)
|
133 |
+
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
134 |
+
elif price_rebate_float > 10000:
|
135 |
+
price_rebate = str(round(price_rebate_float / 100) * 100)
|
136 |
+
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
137 |
+
else:
|
138 |
+
price_rebate = str(round(price_rebate_float / 10) * 10)
|
139 |
else:
|
140 |
+
price_rebate = ""
|
141 |
except (ValueError, TypeError):
|
142 |
+
price_rebate = price_rebate_str
|
143 |
+
|
144 |
+
# Havale indirimi kampanyalı fiyatı yuvarla
|
145 |
+
try:
|
146 |
+
if price_rebate_money_order_str:
|
147 |
+
price_rebate_money_order_float = float(price_rebate_money_order_str)
|
148 |
+
# Fiyat 200000 üzerindeyse en yakın 5000'lik basamağa yuvarla
|
149 |
+
if price_rebate_money_order_float > 200000:
|
150 |
+
price_rebate_money_order = str(round(price_rebate_money_order_float / 5000) * 5000)
|
151 |
+
# Fiyat 30000 üzerindeyse en yakın 1000'lik basamağa yuvarla
|
152 |
+
elif price_rebate_money_order_float > 30000:
|
153 |
+
price_rebate_money_order = str(round(price_rebate_money_order_float / 1000) * 1000)
|
154 |
+
# Fiyat 10000 üzerindeyse en yakın 100'lük basamağa yuvarla
|
155 |
+
elif price_rebate_money_order_float > 10000:
|
156 |
+
price_rebate_money_order = str(round(price_rebate_money_order_float / 100) * 100)
|
157 |
+
# Diğer durumlarda en yakın 10'luk basamağa yuvarla
|
158 |
+
else:
|
159 |
+
price_rebate_money_order = str(round(price_rebate_money_order_float / 10) * 10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
else:
|
161 |
+
price_rebate_money_order = ""
|
162 |
+
except (ValueError, TypeError):
|
163 |
+
price_rebate_money_order = price_rebate_money_order_str
|
164 |
+
|
165 |
+
# Sadece ürün linkini al, resim linkini alma
|
166 |
+
product_link = item.find('productLink').text if item.find('productLink') is not None else ""
|
167 |
+
|
168 |
+
# Tüm fiyat bilgilerini birleştir
|
169 |
+
item_info = (stock_amount, price, product_link, price_eft, price_rebate, price_rebate_money_order)
|
170 |
+
else:
|
171 |
+
# Stokta olmayan ürünler için sadece stok durumunu belirt, fiyat ve link bilgisi verme
|
172 |
+
item_info = (stock_amount, "", "", "", "", "")
|
173 |
|
174 |
+
products.append((name, item_info, full_name))
|
175 |
+
|
176 |
+
# Debug: Ürün sayısını yazdır
|
177 |
+
print(f"Toplam {len(products)} ürün yüklendi")
|
178 |
+
if products:
|
179 |
+
print(f"İlk ürün örneği: {products[0]}")
|
|
|
180 |
|
181 |
# Hugging Face token
|
182 |
hfapi = os.getenv("hfapi")
|
|
|
337 |
|
338 |
# Kullanıcı mesajında ürün ismi geçiyorsa ekle
|
339 |
input_words = user_message.lower().split()
|
340 |
+
user_message_lower = user_message.lower()
|
341 |
+
|
342 |
for product_info in products:
|
343 |
+
# Hem ilk kelimeyi hem de tam ürün adını kontrol et
|
344 |
+
product_first_word = product_info[0] # İlk kelime
|
345 |
+
product_full_name = product_info[2].lower() # Tam ürün adı
|
346 |
+
|
347 |
+
# Eşleşme kontrolü: ilk kelime veya tam ürün adında geçen kelimeler
|
348 |
+
if (product_first_word in input_words or
|
349 |
+
any(word in user_message_lower for word in product_full_name.split() if len(word) > 2)):
|
350 |
if product_info[1][0] == "stokta":
|
351 |
# Kampanyalı fiyat kontrolü
|
352 |
has_campaign = product_info[1][4] and product_info[1][4] != ""
|