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

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.2.tar.gz (4.1 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.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiogram_utcpicker-0.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for aiogram_utcpicker-0.1.2.tar.gz
Algorithm Hash digest
SHA256 833ea0546fe8acbb21ead1508482bc446f048bd4dcfe4dad373e8283e02ea268
MD5 347b7843dc1a0a7e0d081522453d8622
BLAKE2b-256 8199ef968dbfcb657ee93768ea2b8a62ef72d99018f33be197055aef5cf64ee7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiogram_utcpicker-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 20c8a25efcb497253be962a8a578d6e581b4fa04129b08fed4b112896f4e1410
MD5 83fa4728790fddf4e8b0af06b1b1050e
BLAKE2b-256 82d5d9488c285a398dfd88ba52e8a773b7e8bbc95564bb5e2649f8446f0a11b3

See more details on using hashes here.

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