Answer the question
In order to leave comments, you need to log in
How to import data from SQLite to telegram bot?
I have a database in which there are keys, and I need to pull them out from there and send them to the bot, but I don’t know how to do this.
#This is a state handler that should fetch data from the database
@dp.message_handler(chat_id=ADMIN, commands='new_keys')
async def password(message: Message):
await message.answer('На сколько активировать подписку?', reply_markup=kb.markup_view_check)
await View_check.view.set()
@dp.message_handler(chat_id=ADMIN, state=View_check.view)
async def erer(message: Message, state: FSMContext):
# Вот тут нужно продолжить код ( другими словами, вытащить ключ из базы данных и вставить сюда )
await state.finish()
def check_key(key, user_id):
query = f'SELECT key FROM Keys WHERE key = {key}'
status = str(execute_query(query))
if status == '[]':
state = False
else:
if len(str(key)) == 5:
query = f'UPDATE Keys SET key = {random.randint(1000, 100000)} WHERE key = {key}'
execute_query(query)
query = f'UPDATE User SET status_user = 2 WHERE user_id = {user_id}'
execute_query(query)
date_now = str(datetime.utcnow().strftime('%d.%m.%Y'))
query = f'UPDATE User SET date_sub = "{date_now}" WHERE user_id = {user_id}'
execute_query(query)
elif len(str(key)) == 6:
query = f'UPDATE Keys SET key = {random.randint(10000, 1000000)} WHERE key = {key}'
execute_query(query)
query = f'UPDATE User SET status_user = 3 WHERE user_id = {user_id}'
execute_query(query)
query = f'UPDATE User SET date_sub = "вечно" WHERE user_id = {user_id}'
execute_query(query)
state = True
return state
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question