0

Использую pyTelegramBotAPI. Как создать календарь ( calendar-keyboard ) в Python? Я пробовал использовать этот способ: https://github.com/grcanosa/telegram-calendar-keyboard, но по какой-то причине у меня не получилось это сделать. Приведите пожалуйста пример кода, вызывающего календарь.

2 ответа 2

1

Вы используете библиотеку pyTelegramBotAPI, а в коде - python-telegram-bot (https://github.com/python-telegram-bot/python-telegram-bot) Чтобы этот код работал установите pip install python-telegram-bot

0
import logging
from telegram.ext import Updater
from telegram.ext import  CallbackQueryHandler
from telegram.ext import  CommandHandler
from telegram import  ReplyKeyboardRemove


import telegramcalendar


TOKEN = "<ваш токен>"


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

logger = logging.getLogger(__name__)

def calendar_handler(bot,update):
    update.message.reply_text("Please select a date: ",
                        reply_markup=telegramcalendar.create_calendar())


def inline_handler(bot,update):
    selected,date = telegramcalendar.process_calendar_selection(bot, update)
    if selected:
        bot.send_message(chat_id=update.callback_query.from_user.id,
                        text="You selected %s" % (date.strftime("%d/%m/%Y")),
                        reply_markup=ReplyKeyboardRemove())



up = Updater(TOKEN)

up.dispatcher.add_handler(CommandHandler("calendar",calendar_handler))
up.dispatcher.add_handler(CallbackQueryHandler(inline_handler))

up.start_polling()
up.idle()

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.