'How can I add values to the telegram bot keyboard only if this value exists in the database?
My database periodically changes the number of values. I want the values to be displayed in the telegram bot's keyboard only if they exist. How can this be done?
@bot.message_handler(content_types=['text']) def get_date(message): global date date = message.text
db = sqlite3.connect('database.db')
c = db.cursor()
c.execute("SELECT time FROM datetime")
lst = c.fetchall()
print(lst)
btn1 = lst[0][0]
btn2 = lst[0][1]
btn3 = lst[0][2]
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
markup.add(btn1, btn2, btn3, btn4)
bot.send_message(message.from_user.id, 'Выбери доступное время', reply_markup=markup)
bot.register_next_step_handler(message, get_datetime_sure)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
