Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
noXplode committed Nov 27, 2023
1 parent 8fd269f commit 3c9f2e9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@

# Date Selection tool for Aiogram Telegram Bots



## Description

A simple inline calendar, date selection tool for [aiogram](https://github.com/aiogram/aiogram) telegram bots written in Python.

Offers two types of date pickers:

Navigation calendar - user can either select a date or move to the next or previous month/year by clicking a singe button.

Dialog calendar - user selects year on first stage, month on next stage, day on last stage.

From version 0.2 supports aiogram 3, use version 0.1.1 with aiogram 2.


**From version 0.2 supports aiogram 3, use version 0.1.1 with aiogram 2.**



## Usage

Install package

pip install aiogram_calendar


pip install aiogram_calendar

A full working example on how to use aiogram-calendar is provided in *bot_example.py*.

In example keyboard with buttons is created. Each button triggers a calendar in a different way by adding it to a message with a *reply_markup*. Depending on what button of calendar user will press callback is precessed using the *process_selection* method.
A full working example on how to use aiogram-calendar is provided in *`bot_example.py*`.



In example keyboard with buttons is created.

Each button triggers a calendar in a different way by adding it to a message with a *reply_markup*.

reply_markup=await SimpleCalendar().start_calendar()
^^ will reply with a calendar created using English localization (months and days of week captions). Locale can be overridden by passing locale argument:

reply_markup=await SimpleCalendar(locale='uk_UA').start_calendar()
or by getting locale from User data provided by telegram API using get_user_locale method by passing `message.from_user` to it

reply_markup=await SimpleCalendar(locale=await get_user_locale(message.from_user)).start_calendar()

Depending on what button of calendar user will press callback is precessed using the *process_selection* method.

selected, date = await SimpleCalendar(locale=await get_user_locale(callback_query.from_user)).process_selection(callback_query, callback_data)
Here locale is specified from `callback_query.from_user`



## Gif demo:

![aiogram_calendar](https://j.gifs.com/nRQlqW.gif)


![aiogram_calendar](https://j.gifs.com/nRQlqW.gif)
11 changes: 11 additions & 0 deletions aiogram_calendar/tests/test_simple_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ async def test_start_calendar():
assert isinstance(kb[0][1].callback_data, str)


@pytest.mark.asyncio
async def test_start_calendar_locale():
result = await SimpleCalendar(locale='uk_UA').start_calendar()
assert result.inline_keyboard[2][0].text == 'Пн'
assert result.inline_keyboard[2][6].text == 'Нд'

result = await SimpleCalendar(locale='ru_Ru').start_calendar()
assert result.inline_keyboard[2][0].text == 'Пн'
assert result.inline_keyboard[2][6].text == 'Вс'


# checking if we can pass different years & months as start periods
testset = [
(2022, 2, '2022', 'Feb'),
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "aiogram_calendar"
version = "0.3.0"
version = "0.4.0"
description = "Simple Inline Calendar & Date Selection tool for Aiogram Telegram bots"
readme = "README.md"
authors = [{ name = "Andrii Nikolabai", email = "nikolabay.as@gmail.com" }]
Expand All @@ -15,8 +15,6 @@ classifiers = [
'Topic :: Software Development :: Libraries :: Python Modules',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down

0 comments on commit 3c9f2e9

Please sign in to comment.