All Projects → artembakhanov → python-telegram-bot-calendar

artembakhanov / python-telegram-bot-calendar

Licence: MIT license
Python inline calendar for Telegram bots

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to python-telegram-bot-calendar

Zanzara
Asynchronous PHP Telegram Bot Framework built on top of ReactPHP
Stars: ✭ 107 (+50.7%)
Mutual labels:  telegram-bot-api
Haskell Telegram Api
Telegram Bot API for Haskell
Stars: ✭ 184 (+159.15%)
Mutual labels:  telegram-bot-api
python-telegram-bot-seed
Skeleton project for implementing bots in Python using the module python-telegram-bot
Stars: ✭ 25 (-64.79%)
Mutual labels:  telegram-bot-api
Bot Api Base
Clear and simple Telegram bot API
Stars: ✭ 122 (+71.83%)
Mutual labels:  telegram-bot-api
Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+3015.49%)
Mutual labels:  telegram-bot-api
Fosswebsite
A club management system that handles student details, progress, events, achievements, attendance, status updates, teams and workshop registrations. This is the official [email protected] website
Stars: ✭ 242 (+240.85%)
Mutual labels:  telegram-bot-api
Vk To Telegram Bot
Bot for auto-reposting posts from VK to Telegram channel
Stars: ✭ 103 (+45.07%)
Mutual labels:  telegram-bot-api
wptelegram
Integrate your WordPress site perfectly with Telegram with full control.
Stars: ✭ 31 (-56.34%)
Mutual labels:  telegram-bot-api
Java Telegram Bot Tutorial
Java Telegram Bot Tutorial. Feel free to submit issue if you found a mistake.
Stars: ✭ 165 (+132.39%)
Mutual labels:  telegram-bot-api
aiogram-structured
Code your aiogram bot faster, easier & modular.
Stars: ✭ 32 (-54.93%)
Mutual labels:  telegram-bot-api
Botserver
http://telegram.org Bot API Webhooks Framework, for Rubyists
Stars: ✭ 125 (+76.06%)
Mutual labels:  telegram-bot-api
Teledart
A Dart library interfacing with the latest Telegram Bot API.
Stars: ✭ 142 (+100%)
Mutual labels:  telegram-bot-api
Python Telegram
Python client for the Telegram's tdlib
Stars: ✭ 246 (+246.48%)
Mutual labels:  telegram-bot-api
Aiogram
Is a pretty simple and fully asynchronous framework for Telegram Bot API written in Python 3.7 with asyncio and aiohttp.
Stars: ✭ 2,195 (+2991.55%)
Mutual labels:  telegram-bot-api
telegram-bot-dumper
🔪 Dumper & ripper for Telegram bots by token
Stars: ✭ 82 (+15.49%)
Mutual labels:  telegram-bot-api
Android Tg Bot
Awesome Telegram Bot (Android Application)
Stars: ✭ 105 (+47.89%)
Mutual labels:  telegram-bot-api
Rastreiobot
Telegram Bot @RastreioBot
Stars: ✭ 196 (+176.06%)
Mutual labels:  telegram-bot-api
gotgbot
Autogenerated Go wrapper for the telegram API. Inspired by the python-telegram-bot library.
Stars: ✭ 178 (+150.7%)
Mutual labels:  telegram-bot-api
theimagebot
Blog.TheOstrich.Eu.Org
Stars: ✭ 15 (-78.87%)
Mutual labels:  telegram-bot-api
Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+249.3%)
Mutual labels:  telegram-bot-api

python-telegram-bot-calendar

PyPI version CodeFactor cock

Very simple inline calendar for your bot.

Getting Started

This library is tested on Python 3.6 and 3.7.

Installation

pip install python-telegram-bot-calendar

Usage

There is one main class - DetailedTelegramCalendar that can be used as follows. This is the example for pyTelegramBotAPI library. Other libraries are also supported.

from telegram_bot_calendar import DetailedTelegramCalendar, LSTEP

...
@bot.message_handler(commands=['start'])
def start(m):
    calendar, step = DetailedTelegramCalendar().build()
    bot.send_message(m.chat.id,
                     f"Select {LSTEP[step]}",
                     reply_markup=calendar)


@bot.callback_query_handler(func=DetailedTelegramCalendar.func())
def cal(c):
    result, key, step = DetailedTelegramCalendar().process(c.data)
    if not result and key:
        bot.edit_message_text(f"Select {LSTEP[step]}",
                              c.message.chat.id,
                              c.message.message_id,
                              reply_markup=key)
    elif result:
        bot.edit_message_text(f"You selected {result}",
                              c.message.chat.id,
                              c.message.message_id)

In start handler the calendar is created. Several arguments can be passed:

  • calendar_id - small integer or string, used for calendar identification. It used when you need several different calendars (default - 0)
  • current_date - datetime.date object, initial date value (default - today date)
  • additional_buttons - 1D list of buttons that will be added to the bottom of the calendar
  • locale - either en, ru, or eo, can be added more
  • min_date and max_date - both are used as min and max values for the calendar

As you can see, special function that is provided should be passed to callback query handler. It will automatically work. The function takes only one argument - calendar_id that is 0 by default.

In the body of the handler function you need to call process function on callback data. WARNING! You need to create the calendar object again if it was not saved before.

The function process return tuple of size 3 - result, keyboard, step.

  • result - datetime.date object if user finished selecting. Otherwise None
  • keyboard - inline keyboard markup if the result is not ready. Otherwise None
  • step - YEAR, MONTH, or DAY if not ready. None is also possible if there is no change in keyboard.

Advanced use

Several calendars

You can create as many calendars as you want. However, in order to handle them properly set different calendar_id's when you want to distinguish them. Take a look at examples.

Date ranges

In the class constructor min_date and max_date - both are used as min and max values for the calendar. If you add them, the calendar will not show undesired dates. Example: 3

Custom style

You can also write your own code. One of the examples is redefining the steps order.

In the package you can find WMonthTelegramCalendar and WYearTelegramCalendar that start from day and month selecting, not from year.

You can also redefine style parameters. Example:

class MyStyleCalendar(DetailedTelegramCalendar):
    # previous and next buttons style. they are emoji now!
    prev_button = "⬅️"
    next_button = "➡️"
    # you do not want empty cells when month and year are being selected
    empty_month_button = ""
    empty_year_button = ""

You will get:

4

Custom Translation

your_translation_months = list('abcdefghijkl')
your_translation_days_of_week = list('yourtra')

class MyTranslationCalendar(DetailedTelegramCalendar):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.days_of_week['yourtransl'] = your_translation_days_of_week
        self.months['yourtransl'] = your_translation_months

5

Examples

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/yourFeature)
  3. Commit your Changes (git commit -m 'Add some yourFeature')
  4. Push to the Branch (git push origin feature/yourFeature)
  5. Open a Pull Request

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].