как с помощью sql и telebot сделать систему промокодов?
вот что я пытался сделать, но мне всё время выдаёт else хотя в базе другие данные
@dp.message_handler(text_contains=['VVNQHGIC'])
async def promo(message):
connection = pymysql.connect(
host=db_HOST,
port=3306,
user=db_USER,
password=db_PASSWORD,
database=db_NAME,
cursorclass=pymysql.cursors.DictCursor
)
with connection.cursor() as cursor:
insert = f"SELECT `promo` FROM `qiwi_bot` WHERE 1"
connection.commit()
cursor.execute(insert)
promo = cursor.fetchall()
if promo == 'NULL':
await bot.send_message(message.from_user.id, 'Либо такого промокода нет, либо ты его уже использовал❌')
else:
with connection.cursor() as cursor:
insert = f"UPDATE `qiwi_bot` SET `cash` = `cash` + {1000} WHERE id='{message.from_user.id}'"
connection.commit()
cursor.execute(insert)
await bot.send_message(message.from_user.id,'Твой навогодний подарочек это +1000₽ к балансу?')
with connection.cursor() as cursor:
insert = f"UPDATE `qiwi_bot` SET `promo` = 'NULL' WHERE id='{message.from_user.id}'"
connection.commit()
cursor.execute(insert)