diff --git a/README-en.md b/README-en.md index 655dd77..f4d1d48 100644 --- a/README-en.md +++ b/README-en.md @@ -3,7 +3,7 @@

-# aioalice +# aioAlice ## AsyncIO library for Yandex Alice (Yandex Dialogs) @@ -26,9 +26,11 @@ source ./aliceenv/bin/activate pip install pip -U pip install setuptools -U -pip install uvloop # uvloop if you want +pip install uvloop # uvloop if you want, but it can cause some problems -pip install git+https://github.com/surik00/aioalice.git -U +pip install aioalice -U +# Or install from GitHub: +# pip install git+https://github.com/surik00/aioalice.git -U # or if you don't have git installed: # 1. download ZIP diff --git a/README-pypa.md b/README-pypa.md new file mode 100644 index 0000000..3880a24 --- /dev/null +++ b/README-pypa.md @@ -0,0 +1,62 @@ +# aioAlice + +## AsyncIO library for Yandex Alice (Yandex Dialogs) + + +## Why? +- Work with classes, don't bother parsing JSON +- Auto answer to webhook even if you were not fast enough to create answer - there won't be a server error, but you'll get a log +> Auto response will not help if you are not using async IO. So consider not to use any long processing synchronous tasks inside handlers +- Handy handlers to match incoming commands +- Finite-State Machine +- Easy images upload, easy answers generation + + +### Installation + +```bash +# make sure you use virtual env and python 3.6+: +python3.6 -m venv aliceenv +source ./aliceenv/bin/activate + +pip install pip -U +pip install setuptools -U +pip install uvloop # uvloop if you want + +pip install aioalice -U +# Or install from GitHub: +# pip install git+https://github.com/surik00/aioalice.git -U + +# or if you don't have git installed: +# 1. download ZIP +# 2. unarchive and go to dir +# 3. run: +python setup.py install +``` + + +### Quick start + +[Hello alice](https://github.com/surik00/aioalice/blob/master/examples/hello-alice.py) + +```python +dp = Dispatcher() + +@dp.request_handler() +async def handle_all_requests(alice_request): + return alice_request.response('Hello world!') +``` + + +### Cards + +- [All examples](https://github.com/surik00/aioalice/blob/master/examples/README-en.md) + +- [Upload image example](https://github.com/surik00/aioalice/blob/master/examples/upload_image.py) +- [Big Image Card example](https://github.com/surik00/aioalice/blob/master/examples/card_big_image.py) +- [Items List Card example](https://github.com/surik00/aioalice/blob/master/examples/card_items_list.py) + + +### JSON serializing + +If you want to use a faster json library, install [rapidjson](https://github.com/python-rapidjson/python-rapidjson) or [ujson](https://github.com/esnme/ultrajson), it will be detected and used automatically diff --git a/README.md b/README.md index 5678c99..7fac7c8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ # Яндекс Алиса. Диалоги (навыки) -**aioalice** это асинхронная библиотека для взаимодействия с Алисой +**aioAlice** это асинхронная библиотека для взаимодействия с Алисой ## Зачем? @@ -28,7 +28,9 @@ pip install pip -U pip install setuptools -U pip install uvloop # uvloop при желании -pip install git+https://github.com/surik00/aioalice.git -U +pip install aioalice -U +# Or install from GitHub: +# pip install git+https://github.com/surik00/aioalice.git -U # Если git не установлен: # 1. скачайте ZIP diff --git a/aioalice/__init__.py b/aioalice/__init__.py index 012724b..898bcce 100644 --- a/aioalice/__init__.py +++ b/aioalice/__init__.py @@ -11,4 +11,4 @@ asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) -__version__ = '1.1.5' +__version__ = '1.1.6' diff --git a/examples/README-en.md b/examples/README-en.md index d7a1c57..75fdec3 100644 --- a/examples/README-en.md +++ b/examples/README-en.md @@ -10,6 +10,7 @@ - [Buy elephant](buy-elephant.py) - [FSM example \(Finite State Machine\)](FSM_games.py) - [Skip Handlers, log requests](skip_handler_log_everything.py) +- [Handle errors](handle-errors.py) - [Get uploaded images](get_images.py) - [Upload an image](upload_image.py) - [Get quota status and delete an image](quota_status_and_delete_image.py) diff --git a/examples/README.md b/examples/README.md index 4d17f8c..a0c1e26 100644 --- a/examples/README.md +++ b/examples/README.md @@ -10,6 +10,7 @@ - [Купи слона](buy-elephant.py) - [Работа с FSM на примере игры \(Finite State Machine - Машина состояний\)](FSM_games.py) - [Пропускаем хэндлеры, логгируем запросы](skip_handler_log_everything.py) +- [Ловим ошибки](handle-errors.py) - [Проверить загруженные изображения](get_images.py) - [Загрузить изображение](upload_image.py) - [Проверить занятое место и удалить изображение](quota_status_and_delete_image.py) diff --git a/examples/handle-errors.py b/examples/handle-errors.py new file mode 100644 index 0000000..0fb8517 --- /dev/null +++ b/examples/handle-errors.py @@ -0,0 +1,36 @@ +import logging + +from aiohttp import web +from aioalice import Dispatcher, get_new_configured_app + + +logging.basicConfig(format=u'%(filename)s [LINE:%(lineno)d] #%(levelname)-8s [%(asctime)s] %(message)s', + level=logging.INFO) + + +WEBHOOK_URL_PATH = '/my-alice-webhook/' # webhook endpoint + +WEBAPP_HOST = 'localhost' +WEBAPP_PORT = 3001 + +dp = Dispatcher() + + +@dp.request_handler() +async def handle_all_requests(alice_request): + 1 / 0 # some unexpected error + return alice_request.response('Hello world!') + + +# if any error inside handler occur +@dp.errors_handler() +async def the_only_errors_handler(alice_request, e): + # Log the error + logging.error('An error!', exc_info=e) + # Return answer so API doesn't consider your skill non-working + return alice_request.response('Oops! There was an error!') + + +if __name__ == '__main__': + app = get_new_configured_app(dispatcher=dp, path=WEBHOOK_URL_PATH) + web.run_app(app, host=WEBAPP_HOST, port=WEBAPP_PORT) diff --git a/setup.py b/setup.py index f726b82..9ae3733 100644 --- a/setup.py +++ b/setup.py @@ -14,19 +14,19 @@ # Check python version MINIMAL_PY_VERSION = (3, 6) if sys.version_info < MINIMAL_PY_VERSION: - raise RuntimeError('aioalice works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION)))) + raise RuntimeError('aioAlice works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION)))) -__version__ = '1.1.5' +__version__ = '1.1.6' def get_description(): """ - Read full description from 'README.md' + Read full description from 'README-pypa.md' :return: description :rtype: str """ - with open('README.md', 'r', encoding='utf-8') as f: + with open('README-pypa.md', 'r', encoding='utf-8') as f: return f.read() @@ -47,7 +47,7 @@ def get_requirements(filename=None): setup( - name='aioalice', + name='aioAlice', version=__version__, packages=find_packages(exclude=('tests', 'tests.*', 'examples',)), url='https://github.com/surik00/aioalice', @@ -57,6 +57,7 @@ def get_requirements(filename=None): author_email='surenkhorenyan@gmail.com', description='Asynchronous library for Yandex Dialogs (Alice) API', long_description=get_description(), + long_description_content_type='text/markdown', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Console',