Skip to main content

Creates google-like navigation menu using python-telegram-bot wrapper

Project description

python telegram bot menu pagination

Actions Status Maintainability Test Coverage

Description

Makes a google style pagination line for a list of items.

In other words it builds a menu for navigation if you have a lot of search results or whatever list of anything

Installation

pip install ptb-menu-navigation

or if you are working with source code and use Poetry tool:

make install

Usage

from paginator import get_menu

Use get_menu function to create a line of pages

Example:

from paginator import get_menu 
from dataclasses import dataclass

# Define initial menu settings in the dataclass.
@dataclass
class Menu:
    items_per_page: int = 10
    pages_per_line: int = 3
    navigation_signature: str = '±'
    page_label: str = ' p. '

# Add the initial call of get_menu
def handling_input(update, context):
    # ...
    # On first invocation
    navigation = get_menu(total_items=len(search_results),
                          current_page=1,
                          menu_settings=Menu)
    # ...

# Add a callback to handle a page switching  
def navigate(update, context):
    # ...
    navigation = get_menu(total_items=len(search_results),
                          current_page=int(current_page),
                          menu_settings=Menu)     
    # ...            

where search_results is a list of strings and current_page is a number extracted from a callback_data.

See examples/search_bot.py

Demo bot launch

Create a .env file with a TOKEN variable inside of an /examples for launching the demo bot.
eg:
TOKEN=<YOUR_TELEGRAM_BOT_TOKEN_FROM_BOT_FATHER>

You may also provide some additional menu values in the same .env file:

ITEMS_PER_PAGE=1
PAGES_PER_LINE=1
NAVIGATION_SIGNATURE="±"
PAGE_LABEL=" p. "

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

ptb-menu-pagination-0.2.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

ptb_menu_pagination-0.2.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file ptb-menu-pagination-0.2.2.tar.gz.

File metadata

  • Download URL: ptb-menu-pagination-0.2.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Windows/10

File hashes

Hashes for ptb-menu-pagination-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5d041af6f1bd8ddc8a03b59f594da39d0626673d5a7c8b4aba23f9862abc8947
MD5 c667d2a46f2d2b8241e73b009ed037b6
BLAKE2b-256 81b257e9796456d69e2c4c903f83bfb6dff1211896ec3933937c36b2f717fac8

See more details on using hashes here.

File details

Details for the file ptb_menu_pagination-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ptb_menu_pagination-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2b0d7c72d8e4b7836596660ecdc49b905b7a11c7d01ded160e8320fe11be5942
MD5 8eeabb8e7b4eafc0a49625cc041cff3e
BLAKE2b-256 33512c5bb5b970ff099ff11a4a651f09651fa15e6f1bb2cab512ad9774ad4c66

See more details on using hashes here.

Supported by

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