An inline tool for selecting valid timezone differences to UTC
Project description
aiogram_utcpicker
pip install aiogram-utcpicker
UTC selection tool for aiogram3 telegram bots
Use case
The tool is designed to allow users interactively select valid timezones (listed at https://timezonedb.com/time-zones).
To enforce valid timezone selection, the tool has some restrictions:
- Hours: Values only in the range of 0 to 14 (inclusively) are allowed.
- Minutes: Can only be 0, 30 or 45.
Even with the restrictions listed above, it's still possible to select a timezone that is not listed at https://timezonedb.com/time-zones.
If that happens, an error message will be displayed ( as a notification envoked by callback.answer() )
Demo
import logging
import asyncio
import sys
import aiogram.client.default
from aiogram_utcpicker import UtcPickerCallback, start_utc_picker, process_utc_picker
from aiogram import Bot, Dispatcher
from aiogram.enums import ParseMode
from aiogram.filters import Command
from aiogram.filters.callback_data import CallbackData
from aiogram.types import Message, CallbackQuery
dp = Dispatcher()
YOUR_API_TOKEN = ''
@dp.message(Command('utc_picker'))
async def cmd_utc_picker(message: Message):
await message.answer(
'Utc picker demo:\nTry changing the values and submitting\n'
'Only the valid timezones will be accepted, otherwise an error notification will be displayed',
reply_markup=await start_utc_picker()
)
@dp.callback_query(UtcPickerCallback.filter())
async def process_utc_picker_selection(callback: CallbackQuery, callback_data: CallbackData):
canceled, selected, utc_difference = await process_utc_picker(callback, callback_data)
if canceled:
await callback.message.answer('You have canceled utc picker selection')
elif selected:
await callback.message.answer(f'Selected value in minutes: {utc_difference}')
async def main():
bot = Bot(YOUR_API_TOKEN, default=aiogram.client.default.DefaultBotProperties(parse_mode=ParseMode.HTML))
await dp.start_polling(bot)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
Localization
By default, all captions are in english.
To customize text captions, pass a dict with your translations to the start_utc_picker() function
It should have the following structure:
{'cancel_button': 'Cancel',
'confirm_button': 'Confirm',
'display_value': 'Time according to selected: ',
'err_msg_invalid': 'Not a valid timezone'}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiogram_utcpicker-0.1.3.tar.gz.
File metadata
- Download URL: aiogram_utcpicker-0.1.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84d84c7dce40e6c33f622bb48095e97dc81ff996613748b53489a9bf369ef27e
|
|
| MD5 |
686721e052d6962b7daa1bd28c2466a6
|
|
| BLAKE2b-256 |
ef7899989fd04b935b646e483d18be1c2cc532df04cf1594538ef78d30c59b1e
|
Provenance
The following attestation bundles were made for aiogram_utcpicker-0.1.3.tar.gz:
Publisher:
python-publish.yml on alexanderchainsaw/aiogram_utcpicker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_utcpicker-0.1.3.tar.gz -
Subject digest:
84d84c7dce40e6c33f622bb48095e97dc81ff996613748b53489a9bf369ef27e - Sigstore transparency entry: 170338571
- Sigstore integration time:
-
Permalink:
alexanderchainsaw/aiogram_utcpicker@e8e0b4244ef1c096008270a2b1d362c10d7f17bb -
Branch / Tag:
refs/tags/testing - Owner: https://github.com/alexanderchainsaw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e8e0b4244ef1c096008270a2b1d362c10d7f17bb -
Trigger Event:
release
-
Statement type:
File details
Details for the file aiogram_utcpicker-0.1.3-py3-none-any.whl.
File metadata
- Download URL: aiogram_utcpicker-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f09fea30ba335af5ac1cc23d1750b83417d9642693d0e11cb4d30bfed5333090
|
|
| MD5 |
395c5f56ac5b3db711854fe34057918c
|
|
| BLAKE2b-256 |
74e78e3ba58afa062d5b1a03778c430565a54e4122d1040e3b46c177f735e89e
|
Provenance
The following attestation bundles were made for aiogram_utcpicker-0.1.3-py3-none-any.whl:
Publisher:
python-publish.yml on alexanderchainsaw/aiogram_utcpicker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_utcpicker-0.1.3-py3-none-any.whl -
Subject digest:
f09fea30ba335af5ac1cc23d1750b83417d9642693d0e11cb4d30bfed5333090 - Sigstore transparency entry: 170338572
- Sigstore integration time:
-
Permalink:
alexanderchainsaw/aiogram_utcpicker@e8e0b4244ef1c096008270a2b1d362c10d7f17bb -
Branch / Tag:
refs/tags/testing - Owner: https://github.com/alexanderchainsaw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e8e0b4244ef1c096008270a2b1d362c10d7f17bb -
Trigger Event:
release
-
Statement type: