有代码,不明白按键按下时如何加快命令的执行
import sqlite3
import config
import datetime
import telebot
from telebot import types
today = datetime.date.today()
tomorrow = today + datetime.timedelta(days = 1)
today = today.strftime("%d-%m-%Y")
tomorrow = tomorrow.strftime("%d-%m-%Y")
bot = telebot.TeleBot(config.TOKEN)
keyboard_markup = types.ReplyKeyboardMarkup(row_width=2)
btn_today = types.KeyboardButton('today')
btn_tomorrow = types.KeyboardButton('tomorrow')
keyboard_markup.add(btn_today, btn_tomorrow)
@bot.message_handler(commands=["today"])
def add_user_handler(message):
con = sqlite3.connect('schedule.db')
cursor = con.cursor()
sql = ("SELECT * FROM 'schedule' WHERE date=?")
today_sql = (today,)
cursor.execute(sql, today_sql)
today_schedule = cursor.fetchone()
clear_schedule = ''
while today_schedule is not None:
clear_schedule += ("text" + '\n' +
"text: " + str(today_schedule[0]) + '\n' +
"text: "+ str(today_schedule[1]) + '\n' +
"text: " + str(today_schedule[3]) + '\n' +
"text: " + str(today_schedule[4]) + '-' + (today_schedule[5]) + '\n' +
"text: " + str(today_schedule[6]))
today_schedule = cursor.fetchone()
bot.send_message(message.chat.id, clear_schedule, reply_markup=keyboard_markup)
bot.polling(none_stop=True)
当你点击
types.KeyboardButton()这个按钮的值时,代表用户发送到聊天。/例如,机器人通过 执行命令/start,因此:或作为文本捕获:
您可以更改消息处理程序,使其仅适用于某些文本。这是一个例子:
回复按钮“留下邮件和反馈”