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: