Помогите реализовать запрос из SQlite, python? PyTelegramBotApi
нужно сделать запрос в БД (для тг бота) по такой схеме: сначала ищем нужный id пользователя (user_id = message.chat.id), потом нужную дату (который пользователь укажет в команде), и по этой дате выводим задачу. Команда пользователь для запорса даны будет выглядить примерно так: '/show 16.04.22'
Вот код для добавления задачи (на всякий случай)
@bot.message_handler(commands=["add"])
def add(message):
msg = bot.send_message(message.chat.id, "Желаете добавить задачу?")
bot.register_next_step_handler(msg, user_answer)
def user_answer(message):
if message.text.lower() == "да":
msg = bot.send_message(message.chat.id, "Введите дату для задачи: ")
bot.register_next_step_handler(msg, user_date)
elif message.text.lower() == "нет":
bot.send_message(message.chat.id, "ОК!")
else:
bot.send_message(message.chat.id, ntry)
def user_date(message):
global user_date_per
user_date_per = message.text
msg = bot.send_message(message.chat.id, "Введите задачу: ")
bot.register_next_step_handler(msg, user_task)
def user_task(message):
global user_task_per
user_task_per = message.text
people_id = message.chat.id
bot.send_message(message.chat.id, "На дату: "+user_date_per)
bot.send_message(message.chat.id, "Добавлена задача: "+user_task_per)
connect = sqlite3.connect('users.db')
cursor = connect.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS tasks(
id INTEGER,
dates INTEGER,
task INTEGER
)""")
connect.commit()
user_info = "INSERT INTO tasks (id, dates, task) VALUES (:id, :dates, :task)"
cursor.execute(user_info, {'id':people_id, 'dates':user_date_per, 'task':user_task_per})
connect.commit()