Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SergSm/ptb-menu-pagination
🤖ðŸ§Creates google-like navigation menu using python-telegram-bot wrapper
https://github.com/SergSm/ptb-menu-pagination
menu paginate pagination paginator python-telegram-bot python-telegram-bot-menu search-results-pagination telegram telegram-bot telegram-bot-example
Last synced: 2 months ago
JSON representation
🤖ðŸ§Creates google-like navigation menu using python-telegram-bot wrapper
- Host: GitHub
- URL: https://github.com/SergSm/ptb-menu-pagination
- Owner: SergSm
- License: mit
- Created: 2021-12-10T06:33:15.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T06:29:54.000Z (almost 3 years ago)
- Last Synced: 2024-10-05T16:09:45.007Z (4 months ago)
- Topics: menu, paginate, pagination, paginator, python-telegram-bot, python-telegram-bot-menu, search-results-pagination, telegram, telegram-bot, telegram-bot-example
- Language: Python
- Homepage:
- Size: 789 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# python telegram bot menu pagination
![Actions Status](https://github.com/SergSm/ptb-menu-pagination/workflows/ci/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/9eade003d09d837c852e/maintainability)](https://codeclimate.com/github/SergSm/ptb-menu-pagination/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/9eade003d09d837c852e/test_coverage)](https://codeclimate.com/github/SergSm/ptb-menu-pagination/test_coverage)# Description
Makes a google style pagination line for a list of items.
![](https://github.com/SergSm/ptb-menu-pagination/raw/main/example/media/example2.png)
In other words it builds a menu for navigation if you have
a lot of search results or whatever list of anything![](https://github.com/SergSm/ptb-menu-pagination/raw/main/example/media/example3.png)
## Project structure
```
│ .gitignore
│ LICENSE
│ Makefile
│ poetry.lock
│ pyproject.toml
│ README.md
├───.github/
│ └───workflows/
│ ci.yml
├───example/
│ │ search_bot.py
│ │
│ ├───fixtures
│ │ data.txt
│ │
│ └───media/
│ example2.png
│ example3.png
├───paginator/
│ │ consts.py
│ │ main.py
│ │ __init__.py
│ └───composers/
│ map.py
│ menu.py
│ __init__.py
└───tests/
│ test_paginator_get_menu.py
│ __init__.py
└───fixtures/
fixtures.py
```### Installation
```
pip install ptb-menu-navigation
```or if you are working with source code and use Poetry tool:
```
make install
```### Usage
```python
from paginator import get_menu
```Use ```get_menu``` function to create a line of pages
#### Example:
```python
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](https://github.com/SergSm/ptb-menu-pagination/blob/main/example/search_bot.py) bot.\
eg:\
```TOKEN=```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. "
```