From f8d763920a75e694b1e87e40d673971e73a2bce2 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 1 Jun 2025 23:57:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B4=D0=B5=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20Oracle?= =?UTF-8?q?Database=20=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B8=D0=BA=D0=B8=20=D0=B2=20main.py=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8=20=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D0=B2=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8.=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D1=8F=D1=82=D1=81=D1=8F?= =?UTF-8?q?=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20VIN,=20SV?= =?UTF-8?q?IN=20=D0=B8=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D1=8B=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1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0=B0=D0=BD=D1=81=D0=BF=D0=BE=D1=80=D1=82?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=81=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B0=D1=85.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.py | 8 +++++++- main.py | 35 +++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/db.py b/db.py index 6d8e9e6..d1b3754 100644 --- a/db.py +++ b/db.py @@ -54,10 +54,16 @@ class OracleDatabase: (select count(*) from salvagedb.m_JSONS_FROM_NHTSA v3 where v3.svin =s.svin) cnt from (select substr(:vin,1,10) svin, :vin vin from dual) s """ + print(f"[DB DEBUG] Executing query for VIN: {vin}") + print(f"[DB DEBUG] SVIN will be: {vin[:10]}") cur.execute(query, {"vin": vin}) result = cur.fetchone() + print(f"[DB DEBUG] Raw result from database: {result}") if result: - return result[1], result[2], result[3], result[4] # make, model, year, cnt + make, model, year, cnt = result[1], result[2], result[3], result[4] + print(f"[DB DEBUG] Parsed values - make: '{make}', model: '{model}', year: '{year}', cnt: {cnt}") + return make, model, year, cnt + print(f"[DB DEBUG] No result found, returning defaults") return "UNKNOWN", "UNKNOWN", "UNKNOWN", 0 import asyncio return await asyncio.to_thread(_query) diff --git a/main.py b/main.py index 4de0c29..1b7c901 100644 --- a/main.py +++ b/main.py @@ -106,6 +106,10 @@ logging.getLogger().setLevel(logging.INFO) TOKEN = getenv("BOT_TOKEN") BOTNAME = getenv("BOT_NAME") +DECODE_PRICE = getenv("DECODE_PRICE",1) +CHECK_PRICE = getenv("CHECK_PRICE",10) +IMG_PRICE = getenv("IMG_PRICE",100) + oracle_db = OracleDatabase( @@ -228,21 +232,33 @@ async def process_vin(message: Message, state: FSMContext, db: OracleDatabase = try: make, model, year, cnt = await database.fetch_vin_info(vin) logging.info(f"Decode VIN 1st step: make: {make}, model: {model}, year: {year}, cnt: {cnt}") - response_text = f"🚗 **{year} {make} {model}**\n\n" - if cnt == 0: - response_text = "** Unable to decode VIN, possibly incorrect **" + logging.info(f"VIN decode check: make==UNKNOWN: {make == 'UNKNOWN'}, model==UNKNOWN: {model == 'UNKNOWN'}, year==UNKNOWN: {year == 'UNKNOWN'}") + logging.info(f"All UNKNOWN check: {make == 'UNKNOWN' and model == 'UNKNOWN' and year == 'UNKNOWN'}") + logging.info(f"cnt == 0 check: {cnt == 0}") + + # Формируем текст ответа + if make == "UNKNOWN" and model == "UNKNOWN" and year == "UNKNOWN": + logging.info("Setting response_text to 'Unable to decode VIN' because all fields are UNKNOWN") + response_text = "❌ **Unable to decode VIN, possibly incorrect**" + else: + logging.info(f"VIN successfully decoded! Setting response_text to car info: {year} {make} {model}") + response_text = f"🚗 **{year} {make} {model}**\n\n" # Create keyboard based on cnt value builder = InlineKeyboardBuilder() builder.button(text="Try another VIN", callback_data="decode_vin") builder.button(text="Back to Main Menu", callback_data="main_menu") - if cnt > 9: - builder.button(text="Get detailed info. Pay 1 ⭐️", callback_data=f"pay_detailed_info:{vin}", pay=True) + if cnt > 9 and not (make == "UNKNOWN" and model == "UNKNOWN" and year == "UNKNOWN"): + logging.info("Adding detailed info button because cnt > 9 and VIN is decoded") + builder.button(text=f"Get detailed info. Pay {DECODE_PRICE} ⭐️", callback_data=f"pay_detailed_info:{vin}", pay=True) builder.adjust(1, 1, 1) # Each button on separate row else: + logging.info(f"Not adding detailed info button because cnt <= 9 (cnt={cnt}) or VIN not decoded") builder.adjust(1, 1) # Each button on separate row + logging.info(f"Final response_text before sending in decode VIN: '{response_text}'") + logging.info(f"Response text length: {len(response_text)}") await message.answer(response_text, reply_markup=builder.as_markup(), parse_mode="Markdown") except Exception as e: @@ -271,11 +287,16 @@ async def process_check_vin(message: Message, state: FSMContext, db: OracleDatab salvage_count = await database.count_salvage_records(vin) logging.info(f"Check VIN: make: {make}, model: {model}, year: {year}, cnt: {cnt}, salvage_count: {salvage_count}") + logging.info(f"VIN decode check: make==UNKNOWN: {make == 'UNKNOWN'}, model==UNKNOWN: {model == 'UNKNOWN'}, year==UNKNOWN: {year == 'UNKNOWN'}") + logging.info(f"All UNKNOWN check: {make == 'UNKNOWN' and model == 'UNKNOWN' and year == 'UNKNOWN'}") + logging.info(f"cnt == 0 check: {cnt == 0}") # Формируем текст ответа - if cnt == 0: + if make == "UNKNOWN" and model == "UNKNOWN" and year == "UNKNOWN": + logging.info("Setting response_text to 'Unable to decode VIN' because all fields are UNKNOWN") response_text = "❌ **Unable to decode VIN, possibly incorrect**\n\n" else: + logging.info(f"VIN successfully decoded! Setting response_text to car info: {year} {make} {model}") response_text = f"🚗 **{year} {make} {model}**\n\n" response_text += f"📊 **Records found in database:** {salvage_count}\n\n" @@ -296,6 +317,8 @@ async def process_check_vin(message: Message, state: FSMContext, db: OracleDatab builder.button(text="Back to Main Menu", callback_data="main_menu") builder.adjust(1, 1) # Each button on separate row + logging.info(f"Final response_text before sending: '{response_text}'") + logging.info(f"Response text length: {len(response_text)}") await message.answer(response_text, reply_markup=builder.as_markup(), parse_mode="Markdown") except Exception as e: