-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: python | ||
python: | ||
- "3.5" | ||
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
- "3.9-dev" | ||
- "nightly" | ||
# command to install dependencies | ||
install: | ||
- pip install -r requirements.txt | ||
# command to run tests | ||
script: | ||
- pytest tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# callbaker | ||
# 👨🍳 callbaker | ||
Telegram callback queries converter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
This module contains all the necessary functions for | ||
creating callback data strings and parsing it from call's data. | ||
""" | ||
|
||
EXTERNAL_MARK_SEPARATOR = "&" | ||
INTERNAL_MARK_SEPARATOR = "=" | ||
DEFAULT_MARK_VALUE = "*" | ||
EMS = EXTERNAL_MARK_SEPARATOR | ||
IMS = INTERNAL_MARK_SEPARATOR | ||
DMV = DEFAULT_MARK_VALUE | ||
|
||
|
||
def info_from_callback(call_data: str, separators: tuple = (EMS, IMS, DMV)) -> dict: | ||
""" | ||
:param call_data: | ||
:param separators: | ||
:return: | ||
""" | ||
|
||
_ems, _ims, _ = separators | ||
separated_items = call_data.split(_ems) | ||
parsed_items = [element.split(_ims) | ||
for element in separated_items if element] | ||
result = {k: v for k, v in parsed_items if k and v} | ||
|
||
for mark, value in result.items(): | ||
if value.isdigit(): | ||
result[mark] = int(value) | ||
_ = [result.update({mark: item}) for item in (False, True, None) if value == str(item)] | ||
return result | ||
|
||
|
||
def callback_from_info(info: dict, separators: tuple = (EMS, IMS, DMV)) -> str: | ||
""" | ||
:param info: | ||
:param separators: | ||
:return: | ||
""" | ||
_ems, _ims, _ = separators | ||
return "".join(["%s%s%s%s" % (_ems, mark, _ims, value) for mark, value in info.items()]) | ||
|
||
|
||
if __name__ == "__main__": | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest==5.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Setup package module | ||
""" | ||
|
||
from distutils.core import setup | ||
|
||
setup( | ||
name='callbaker', | ||
packages=['callbaker'], | ||
version='1.0.0', | ||
license='MIT', | ||
description="Telegram Button Callback Data Converter", | ||
author='torrua', | ||
author_email='torrua@gmail.com', | ||
url='https://github.com/torrua/callbaker', | ||
download_url='https://github.com/torrua/callbaker/archive/v1.0.0.tar.gz', | ||
keywords=['Convert', 'Callback', 'Keyboard', 'Telegram', "Inline"], | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', # "3 - Alpha", "4 - Beta" or "5 - Production/Stable" | ||
'Intended Audience :: Developers', | ||
'Topic :: Software Development :: Build Tools', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
], | ||
) |