From 7fb083fe07a6d822e3e043626e218e55d50a3063 Mon Sep 17 00:00:00 2001 From: torrua Date: Thu, 9 Apr 2020 08:00:12 +0700 Subject: [PATCH] RELEASE 1.0.0 --- .travis.yml | 14 +++++++++++++ README.md | 2 +- callbaker/__init__.py | 48 +++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + setup.cfg | 2 ++ setup.py | 29 ++++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 callbaker/__init__.py create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5f15a4c --- /dev/null +++ b/.travis.yml @@ -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/ \ No newline at end of file diff --git a/README.md b/README.md index 85f522f..50c0ca8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# callbaker +# 👨‍🍳 callbaker Telegram callback queries converter diff --git a/callbaker/__init__.py b/callbaker/__init__.py new file mode 100644 index 0000000..2cfdb5b --- /dev/null +++ b/callbaker/__init__.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ca6b421 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest==5.4.1 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..73f743c --- /dev/null +++ b/setup.py @@ -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', + ], +)