Skip to content

Commit

Permalink
RELEASE 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
torrua committed Apr 9, 2020
1 parent 3b568ba commit 7fb083f
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .travis.yml
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/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# callbaker
# 👨‍🍳 callbaker
Telegram callback queries converter
48 changes: 48 additions & 0 deletions callbaker/__init__.py
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==5.4.1
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
29 changes: 29 additions & 0 deletions setup.py
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',
],
)

0 comments on commit 7fb083f

Please sign in to comment.