Skip to main content

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

img.png

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

aiogram_utcpicker-0.1.4.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogram_utcpicker-0.1.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_utcpicker-0.1.4.tar.gz.

File metadata

  • Download URL: aiogram_utcpicker-0.1.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for aiogram_utcpicker-0.1.4.tar.gz
Algorithm Hash digest
SHA256 880b35424e26f4bf4e88f4eb410215a8e4b77b9503c1e551c24d44f45f5bccbe
MD5 2df2929e5997e79b99ab8c76ab893715
BLAKE2b-256 c517829afd42901382f002c0dc38b6c04bdd97f7c846bedaffd39bf4ec9127e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_utcpicker-0.1.4.tar.gz:

Publisher: python-publish.yml on alexanderchainsaw/aiogram_utcpicker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiogram_utcpicker-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_utcpicker-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca5d5fc139fa963d9540ac66df23f60e0a9ecd43be388a15c025ffe4e6c13aba
MD5 0715478f53e3d32dec3d076e4dd2fcd2
BLAKE2b-256 1f970df00a99a7bf070bb50b78fbbce1aa894cb23bacc43bc7a947b789342b30

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_utcpicker-0.1.4-py3-none-any.whl:

Publisher: python-publish.yml on alexanderchainsaw/aiogram_utcpicker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page