From 9faa248f01c9920cb40587a9e5500798f96bf2ac Mon Sep 17 00:00:00 2001 From: Ali Nikneshan Date: Thu, 25 Oct 2018 10:05:13 +0330 Subject: [PATCH 01/30] change make keyboard to staticmethod This helps using make_keyboard before creating bot instance. Aslo does not impact current usage --- client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client.py b/client.py index 92d71ea..20b0290 100644 --- a/client.py +++ b/client.py @@ -217,8 +217,8 @@ def change_keyboard(self, to, keyboard): } return self.send_message(post_data) - - def make_keyboard(self, keyboard_data): + @staticmethod + def make_keyboard(keyboard_data): keyboard = [] if isinstance(keyboard_data, str): From 1b20cb8efcb4e2ffdaab99dbcae93d1993cf1164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 12:58:23 +0330 Subject: [PATCH 02/30] packaging --- .editorconfig | 21 + .github/ISSUE_TEMPLATE.md | 15 + .gitignore | 102 +++++ .idea/inspectionProfiles/Project_Default.xml | 32 ++ .idea/misc.xml | 85 ++++ .idea/modules.xml | 9 + .idea/soroush_python_sdk.iml | 12 + .idea/vcs.xml | 7 + .idea/workspace.xml | 409 ++++++++++++++++++ .travis.yml | 29 ++ AUTHORS.rst | 13 + CONTRIBUTING.rst | 128 ++++++ HISTORY.rst | 8 + LICENSE | 22 + MANIFEST.in | 11 + Makefile | 88 ++++ README.md | 12 +- README.rst | 41 ++ docs/Makefile | 20 + docs/authors.rst | 1 + docs/conf.py | 163 +++++++ docs/contributing.rst | 1 + docs/history.rst | 1 + docs/index.rst | 20 + docs/installation.rst | 51 +++ docs/make.bat | 36 ++ docs/readme.rst | 1 + docs/usage.rst | 7 + examples/download_file.py | 6 +- examples/echo_bot.py | 4 +- examples/get_messages.py | 7 +- examples/send_attachment.py | 7 +- examples/send_change_keyboard.py | 5 +- examples/send_image.py | 5 +- examples/send_location.py | 5 +- examples/send_text.py | 5 +- examples/send_text_with_keyboard.py | 4 +- examples/send_video.py | 5 +- examples/send_voice.py | 5 +- requirements_dev.txt | 12 + setup.cfg | 26 ++ setup.py | 50 +++ soroush_python_sdk/__init__.py | 9 + .../soroush_python_sdk.py | 3 + tests/test_soroush_python_sdk.py | 25 ++ tox.ini | 28 ++ 46 files changed, 1519 insertions(+), 37 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/soroush_python_sdk.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 .travis.yml create mode 100644 AUTHORS.rst create mode 100644 CONTRIBUTING.rst create mode 100644 HISTORY.rst create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 README.rst create mode 100644 docs/Makefile create mode 100644 docs/authors.rst create mode 100755 docs/conf.py create mode 100644 docs/contributing.rst create mode 100644 docs/history.rst create mode 100644 docs/index.rst create mode 100644 docs/installation.rst create mode 100644 docs/make.bat create mode 100644 docs/readme.rst create mode 100644 docs/usage.rst create mode 100644 requirements_dev.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 soroush_python_sdk/__init__.py rename client.py => soroush_python_sdk/soroush_python_sdk.py (99%) create mode 100644 tests/test_soroush_python_sdk.py create mode 100644 tox.ini diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d4a2c44 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +end_of_line = lf + +[*.bat] +indent_style = tab +end_of_line = crlf + +[LICENSE] +insert_final_newline = false + +[Makefile] +indent_style = tab diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..f4a65b8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,15 @@ +* Soroush Python SDK version: +* Python version: +* Operating System: + +### Description + +Describe what you were trying to get done. +Tell us what happened, what went wrong, and what you expected to happen. + +### What I Did + +``` +Paste the command(s) you ran and the output. +If there was a crash, please include the traceback here. +``` diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84229f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..10d6348 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,32 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4dcc4f6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..534240d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/soroush_python_sdk.iml b/.idea/soroush_python_sdk.iml new file mode 100644 index 0000000..a5c7a3e --- /dev/null +++ b/.idea/soroush_python_sdk.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..7f85927 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4caafa1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,409 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - 1540450010717 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/_static/.gitdir b/docs/_static/.gitdir new file mode 100644 index 0000000..e69de29 diff --git a/docs/index.rst b/docs/index.rst index 0f4f466..12996f8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,5 +1,5 @@ Welcome to Soroush Python SDK's documentation! -====================================== +============================================== .. toctree:: :maxdepth: 2 diff --git a/docs/modules.rst b/docs/modules.rst new file mode 100644 index 0000000..704fc1e --- /dev/null +++ b/docs/modules.rst @@ -0,0 +1,7 @@ +soroush_python_sdk +================== + +.. toctree:: + :maxdepth: 4 + + soroush_python_sdk diff --git a/docs/readme.rst b/docs/readme.rst index 72a3355..9351b57 100644 --- a/docs/readme.rst +++ b/docs/readme.rst @@ -1 +1,71 @@ -.. include:: ../README.rst +Soroush Messenger Bot Python SDK +================================ + +Soroush Messenger Bot Wrapper for Python |shiled| |travis| |badge| +|Documentation Status| |Updates| + +Dependencies +------------ + +- Python 2.7+ +- requests +- sseclient-py + +Installation +------------ + +.. code:: bash + + pip install soroush-python-sdk + +Run the below commands + +.. code:: bash + + git clone https://github.com/soroush-app/bot-python-sdk + cd bot-python-sdk + pip install -r requirements.txt + +Usage +----- + +.. code:: python + + from soroush_python_sdk import Client + + bot_token = 'your bot token' + + bot = Client(bot_token) + + try: + to = 'user chat_id' + + [error, success] = bot.send_text(to, 'Your text') + + if success: + print('Message sent successfully') + else: + print('Sending message failed: {}' .format(error)) + + except Exception as e: + print(e.args[0]) + +“to” value in above example is chat_id of a bot user. You can find it in +front of ‘from’ key in a message that user has sent to your bot. You can +see more examples in the `examples`_ directory. + +## Contribute ## Contributions to the package are always welcome! - +Report any idea, bugs or issues you find on the `issue tracker`_. - You +can grab the source code at the package’s `Git repository`_. + +.. _examples: https://github.com/soroush-app/bot-python-sdk/tree/master/examples +.. _issue tracker: https://github.com/soroush-app/bot-python-sdk/issues +.. _Git repository: https://github.com/soroush-app/bot-python-sdk.git + +.. |shiled| image:: https://img.shields.io/pypi/v/soroush_python_sdk.svg +.. |travis| image:: https://img.shields.io/travis/alinik/soroush_python_sdk.svg +.. |badge| image:: https://readthedocs.org/projects/soroush-python-sdk/badge/?version=latest +.. |Documentation Status| image:: https://readthedocs.org/projects/bot-python-sdk/badge/?version=latest + :target: https://bot-python-sdk.readthedocs.io/en/latest/?badge=latest +.. |Updates| image:: https://pyup.io/repos/github/alinik/bot-python-sdk/shield.svg + :target: https://pyup.io/repos/github/alinik/bot-python-sdk/ diff --git a/docs/soroush_python_sdk.rst b/docs/soroush_python_sdk.rst new file mode 100644 index 0000000..255dd33 --- /dev/null +++ b/docs/soroush_python_sdk.rst @@ -0,0 +1,22 @@ +soroush\_python\_sdk package +============================ + +Submodules +---------- + +soroush\_python\_sdk.soroush\_python\_sdk module +------------------------------------------------ + +.. automodule:: soroush_python_sdk.soroush_python_sdk + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: soroush_python_sdk + :members: + :undoc-members: + :show-inheritance: From 83e8c4ff5358012b62e18bf4e5fd3b0683a87391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 13:55:10 +0330 Subject: [PATCH 14/30] =?UTF-8?q?Bump=20version:=200.2.0=20=E2=86=92=200.2?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 2 +- setup.py | 2 +- soroush_python_sdk/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 4eebcd2..c49ec57 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.0 +current_version = 0.2.1 commit = True tag = True diff --git a/setup.py b/setup.py index 38ece8d..e850c58 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='0.2.0', + version='0.2.1', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index 1f56878..7bb3063 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '0.2.0' +__version__ = '0.2.1' from .soroush_python_sdk import Client From 8da5032e0b9ba4276de1bffd7afdb9bedc83f226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 13:59:37 +0330 Subject: [PATCH 15/30] doc fixing --- README.rst | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/readme.rst | 72 +------------------------------------------------ 2 files changed, 72 insertions(+), 71 deletions(-) create mode 100644 README.rst diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..9351b57 --- /dev/null +++ b/README.rst @@ -0,0 +1,71 @@ +Soroush Messenger Bot Python SDK +================================ + +Soroush Messenger Bot Wrapper for Python |shiled| |travis| |badge| +|Documentation Status| |Updates| + +Dependencies +------------ + +- Python 2.7+ +- requests +- sseclient-py + +Installation +------------ + +.. code:: bash + + pip install soroush-python-sdk + +Run the below commands + +.. code:: bash + + git clone https://github.com/soroush-app/bot-python-sdk + cd bot-python-sdk + pip install -r requirements.txt + +Usage +----- + +.. code:: python + + from soroush_python_sdk import Client + + bot_token = 'your bot token' + + bot = Client(bot_token) + + try: + to = 'user chat_id' + + [error, success] = bot.send_text(to, 'Your text') + + if success: + print('Message sent successfully') + else: + print('Sending message failed: {}' .format(error)) + + except Exception as e: + print(e.args[0]) + +“to” value in above example is chat_id of a bot user. You can find it in +front of ‘from’ key in a message that user has sent to your bot. You can +see more examples in the `examples`_ directory. + +## Contribute ## Contributions to the package are always welcome! - +Report any idea, bugs or issues you find on the `issue tracker`_. - You +can grab the source code at the package’s `Git repository`_. + +.. _examples: https://github.com/soroush-app/bot-python-sdk/tree/master/examples +.. _issue tracker: https://github.com/soroush-app/bot-python-sdk/issues +.. _Git repository: https://github.com/soroush-app/bot-python-sdk.git + +.. |shiled| image:: https://img.shields.io/pypi/v/soroush_python_sdk.svg +.. |travis| image:: https://img.shields.io/travis/alinik/soroush_python_sdk.svg +.. |badge| image:: https://readthedocs.org/projects/soroush-python-sdk/badge/?version=latest +.. |Documentation Status| image:: https://readthedocs.org/projects/bot-python-sdk/badge/?version=latest + :target: https://bot-python-sdk.readthedocs.io/en/latest/?badge=latest +.. |Updates| image:: https://pyup.io/repos/github/alinik/bot-python-sdk/shield.svg + :target: https://pyup.io/repos/github/alinik/bot-python-sdk/ diff --git a/docs/readme.rst b/docs/readme.rst index 9351b57..72a3355 100644 --- a/docs/readme.rst +++ b/docs/readme.rst @@ -1,71 +1 @@ -Soroush Messenger Bot Python SDK -================================ - -Soroush Messenger Bot Wrapper for Python |shiled| |travis| |badge| -|Documentation Status| |Updates| - -Dependencies ------------- - -- Python 2.7+ -- requests -- sseclient-py - -Installation ------------- - -.. code:: bash - - pip install soroush-python-sdk - -Run the below commands - -.. code:: bash - - git clone https://github.com/soroush-app/bot-python-sdk - cd bot-python-sdk - pip install -r requirements.txt - -Usage ------ - -.. code:: python - - from soroush_python_sdk import Client - - bot_token = 'your bot token' - - bot = Client(bot_token) - - try: - to = 'user chat_id' - - [error, success] = bot.send_text(to, 'Your text') - - if success: - print('Message sent successfully') - else: - print('Sending message failed: {}' .format(error)) - - except Exception as e: - print(e.args[0]) - -“to” value in above example is chat_id of a bot user. You can find it in -front of ‘from’ key in a message that user has sent to your bot. You can -see more examples in the `examples`_ directory. - -## Contribute ## Contributions to the package are always welcome! - -Report any idea, bugs or issues you find on the `issue tracker`_. - You -can grab the source code at the package’s `Git repository`_. - -.. _examples: https://github.com/soroush-app/bot-python-sdk/tree/master/examples -.. _issue tracker: https://github.com/soroush-app/bot-python-sdk/issues -.. _Git repository: https://github.com/soroush-app/bot-python-sdk.git - -.. |shiled| image:: https://img.shields.io/pypi/v/soroush_python_sdk.svg -.. |travis| image:: https://img.shields.io/travis/alinik/soroush_python_sdk.svg -.. |badge| image:: https://readthedocs.org/projects/soroush-python-sdk/badge/?version=latest -.. |Documentation Status| image:: https://readthedocs.org/projects/bot-python-sdk/badge/?version=latest - :target: https://bot-python-sdk.readthedocs.io/en/latest/?badge=latest -.. |Updates| image:: https://pyup.io/repos/github/alinik/bot-python-sdk/shield.svg - :target: https://pyup.io/repos/github/alinik/bot-python-sdk/ +.. include:: ../README.rst From 96d3a63b3da78946e6923f39a1697677cc4ae5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 14:01:06 +0330 Subject: [PATCH 16/30] =?UTF-8?q?Bump=20version:=200.2.1=20=E2=86=92=200.2?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- soroush_python_sdk/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index e850c58..9263bb9 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='0.2.1', + version='version='0.2.1'', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index 7bb3063..6b54478 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '0.2.1' +__version__ = '__version__ = '0.2.1'' from .soroush_python_sdk import Client From f0baa2f30d0f950f14c5cc0a6509e152cd361c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 14:01:57 +0330 Subject: [PATCH 17/30] =?UTF-8?q?Bump=20version:=200.2.1=20=E2=86=92=200.2?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- soroush_python_sdk/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 9263bb9..b1edb1a 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='version='0.2.1'', + version='version='version='0.2.1''', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index 6b54478..f9a084e 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '__version__ = '0.2.1'' +__version__ = '__version__ = '__version__ = '0.2.1''' from .soroush_python_sdk import Client From 057b87dc3dce2bb206c2b05a43a1b0d2cfb01c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 14:09:02 +0330 Subject: [PATCH 18/30] fix bumpversion issue --- setup.cfg | 4 ---- setup.py | 2 +- soroush_python_sdk/__init__.py | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index c49ec57..8931238 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,12 +4,8 @@ commit = True tag = True [bumpversion:file:setup.py] -search = version='{current_version}' -replace = version='{new_version}' [bumpversion:file:soroush_python_sdk/__init__.py] -search = __version__ = '{current_version}' -replace = __version__ = '{new_version}' [bdist_wheel] universal = 1 diff --git a/setup.py b/setup.py index b1edb1a..e850c58 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='version='version='0.2.1''', + version='0.2.1', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index f9a084e..7bb3063 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '__version__ = '__version__ = '0.2.1''' +__version__ = '0.2.1' from .soroush_python_sdk import Client From 91e4fae8e59104c247851a7a17a789bbba817cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 14:12:57 +0330 Subject: [PATCH 19/30] test bump --- setup.cfg | 2 +- setup.py | 4 ++-- soroush_python_sdk/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 8931238..6d45445 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.1 +current_version = 0.2.2 commit = True tag = True diff --git a/setup.py b/setup.py index e850c58..8d3b389 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ with open('HISTORY.rst') as history_file: history = history_file.read() -requirements = [ ] +requirements = [] setup_requirements = ['pytest-runner', ] @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='0.2.1', + version='0.2.2', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index 7bb3063..6dc1670 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '0.2.1' +__version__ = '0.2.2' from .soroush_python_sdk import Client From d57c5e670da49f5afd63ade90667ed4dceed3220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 14:14:44 +0330 Subject: [PATCH 20/30] =?UTF-8?q?Bump=20version:=200.2.2=20=E2=86=92=200.2?= =?UTF-8?q?.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 2 +- setup.py | 2 +- soroush_python_sdk/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6d45445..85ded0a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.2 +current_version = 0.2.3 commit = True tag = True diff --git a/setup.py b/setup.py index 8d3b389..4b305f0 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='0.2.2', + version='0.2.3', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index 6dc1670..5bd6328 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '0.2.2' +__version__ = '0.2.3' from .soroush_python_sdk import Client From d577d6a37fc90dd2ef9383d536273c6e9ec29125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 16:05:18 +0330 Subject: [PATCH 21/30] update to new modifications --- soroush_python_sdk/soroush_python_sdk.py | 55 +++++++++++++----------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/soroush_python_sdk/soroush_python_sdk.py b/soroush_python_sdk/soroush_python_sdk.py index 13ba85d..0b0f75c 100644 --- a/soroush_python_sdk/soroush_python_sdk.py +++ b/soroush_python_sdk/soroush_python_sdk.py @@ -5,24 +5,26 @@ import sseclient import json import os +from time import sleep class Client: + HEADERS = {'Content-Type': 'Application/json', 'Accept': 'Application/json'} + BASE_URL = 'https://bot.sapp.ir/' + GET_MESSAGE_URL = '/getMessage' + SEND_MESSAGE_URL = '/sendMessage' + DOWNLOAD_FILE_URL = '/downloadFile/' + UPLOAD_FILE_URL = '/uploadFile' + RETRY_DELAY = 10 def __init__(self, token): - self.base_url = 'https://bot.sapp.ir/' - self.get_message_url = '/getMessage' - self.send_message_url = '/sendMessage' - self.download_file_url = '/downloadFile/' - self.upload_file_url = '/uploadFile' self.token = token - self.retry_delay = 3 def get_upload_file_url(self): if not self.token: raise ValueError('Invalid bot token') - return self.base_url + self.token + self.upload_file_url + return self.BASE_URL + self.token + self.UPLOAD_FILE_URL def get_download_file_url(self, file_url): if not self.token: @@ -30,39 +32,41 @@ def get_download_file_url(self, file_url): if not file_url: raise ValueError('Invalid file url') - return self.base_url + self.token + self.download_file_url + file_url + return self.BASE_URL + self.token + self.DOWNLOAD_FILE_URL + file_url def get_messages(self): if not self.token: raise ValueError('Invalid bot token') - url = self.base_url + self.token + self.get_message_url + url = self.BASE_URL + self.token + self.GET_MESSAGE_URL - response = requests.get(url, stream=True) - if 'Content-Type' in response.headers: - client = sseclient.SSEClient(response) + while True: + response = requests.get(url, stream=True) + if 'Content-Type' in response.headers: + client = sseclient.SSEClient(response) - for event in client.events(): - try: - message_event = json.loads(event.data) - yield message_event - except Exception as e: - print(e.args[0]) - continue - else: - raise ValueError('Invalid bot token') + for event in client.events(): + try: + message_event = json.loads(event.data) + yield message_event + except Exception as e: + print(e.args[0]) + continue + else: + print('Invalid bot token OR Invalid connection response from server') + + sleep(self.RETRY_DELAY) def send_message(self, post_data): if not self.token: raise ValueError('Invalid bot token') - url = self.base_url + self.token + self.send_message_url - headers = {'Content-Type': 'Application/json', 'Accept': 'Application/json'} + url = self.BASE_URL + self.token + self.SEND_MESSAGE_URL post_data = json.dumps(post_data, separators=(',', ':')) try: - response = requests.post(url, post_data, headers=headers) + response = requests.post(url, post_data, headers=self.HEADERS) if response: response_json = json.loads(response.text) @@ -220,6 +224,7 @@ def change_keyboard(self, to, keyboard): } return self.send_message(post_data) + @staticmethod def make_keyboard(keyboard_data): keyboard = [] @@ -341,5 +346,3 @@ def upload_file(self, file_path): return ['Bad Response: ' + str(response.status_code) + ' status code', False] except Exception as e: return [e.args[0], False] - - From 88a04c3bb2254d35b6ba3dfdc942ef20f27adcc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B9=D9=84=DB=8C=20=D9=86=DB=8C=DA=A9=20=D9=86=D8=B4?= =?UTF-8?q?=D8=A7=D9=86?= Date: Thu, 25 Oct 2018 16:06:55 +0330 Subject: [PATCH 22/30] =?UTF-8?q?Bump=20version:=200.2.3=20=E2=86=92=200.2?= =?UTF-8?q?.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 2 +- setup.py | 2 +- soroush_python_sdk/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 85ded0a..1ff8222 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.3 +current_version = 0.2.4 commit = True tag = True diff --git a/setup.py b/setup.py index 4b305f0..0295fec 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/alinik/soroush_python_sdk', - version='0.2.3', + version='0.2.4', zip_safe=False, ) diff --git a/soroush_python_sdk/__init__.py b/soroush_python_sdk/__init__.py index 5bd6328..b942288 100644 --- a/soroush_python_sdk/__init__.py +++ b/soroush_python_sdk/__init__.py @@ -4,6 +4,6 @@ __author__ = """Ali Nikneshan""" __email__ = 'ali@nikneshan.com' -__version__ = '0.2.3' +__version__ = '0.2.4' from .soroush_python_sdk import Client From 0af03d7af633d78b5fffe78c3b84798398d36807 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 4 Nov 2018 20:23:26 +0330 Subject: [PATCH 23/30] Update pytest from 3.9.2 to 3.10.0 --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 8ac995b..f4c9d40 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -8,5 +8,5 @@ coverage==4.5.1 Sphinx==1.8.1 twine==1.12.1 -pytest==3.9.2 +pytest==3.10.0 pytest-runner==4.2 From fac9e7fa0e5cb0d37d7a94fa7cdf896306ed9da5 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Thu, 8 Nov 2018 21:35:33 +0330 Subject: [PATCH 24/30] Update requests from 2.20.0 to 2.20.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 67b1edb..790f850 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests==2.20.0 +requests==2.20.1 sseclient-py==1.7 From b4c9d57fa55bd11403f8ed25cc4a5504c4de8277 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 11 Nov 2018 10:46:39 +0330 Subject: [PATCH 25/30] Update sphinx from 1.8.1 to 1.8.2 --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index f4c9d40..56e4545 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -5,7 +5,7 @@ watchdog==0.9.0 flake8==3.6.0 tox==3.5.2 coverage==4.5.1 -Sphinx==1.8.1 +Sphinx==1.8.2 twine==1.12.1 pytest==3.10.0 From 869e2e25e7195d34fb3218c4df19f007720875b5 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 10 Dec 2018 19:50:39 +0330 Subject: [PATCH 26/30] Update requests from 2.20.1 to 2.21.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 790f850..5e6da72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests==2.20.1 +requests==2.21.0 sseclient-py==1.7 From a563bd99f49da2bb8255200d04d92854a1a578cc Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 10 Mar 2019 20:04:23 +0330 Subject: [PATCH 27/30] Update coverage from 4.5.1 to 4.5.3 --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 56e4545..33088ec 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -4,7 +4,7 @@ wheel==0.32.2 watchdog==0.9.0 flake8==3.6.0 tox==3.5.2 -coverage==4.5.1 +coverage==4.5.3 Sphinx==1.8.2 twine==1.12.1 From f4dfc0382c49cf1d46518715b5b8ae5ee976e587 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 1 Apr 2019 03:16:28 +0430 Subject: [PATCH 28/30] Update pytest from 3.10.0 to 4.4.0 --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 56e4545..95d2619 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -8,5 +8,5 @@ coverage==4.5.1 Sphinx==1.8.2 twine==1.12.1 -pytest==3.10.0 +pytest==4.4.0 pytest-runner==4.2 From fa29f0b76e4d1bc4815ef08befdfa3cc9c2a4452 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Wed, 3 Apr 2019 21:50:33 +0430 Subject: [PATCH 29/30] Update tox from 3.5.2 to 3.8.6 --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 56e4545..4feb97c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -3,7 +3,7 @@ bumpversion==0.5.3 wheel==0.32.2 watchdog==0.9.0 flake8==3.6.0 -tox==3.5.2 +tox==3.8.6 coverage==4.5.1 Sphinx==1.8.2 twine==1.12.1 From e2dbb4c9891a0ab9d391045378f228903839ea3a Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 8 Apr 2019 20:54:49 +0430 Subject: [PATCH 30/30] Update sphinx from 1.8.2 to 2.0.1 --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 56e4545..40e6a53 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -5,7 +5,7 @@ watchdog==0.9.0 flake8==3.6.0 tox==3.5.2 coverage==4.5.1 -Sphinx==1.8.2 +Sphinx==2.0.1 twine==1.12.1 pytest==3.10.0