From ab14a664c40691be3b8d5ceda55b6539c8826fc6 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 30 Oct 2017 02:15:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B0=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B1=D0=B0=D0=BB=D0=B0=D0=BD=D1=81=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=B6=D0=B0=D0=BB=D0=BE=D0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aio_test.py | 6 +++ python3_anticaptcha/aioAntiCaptchaControl.py | 49 ++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 aio_test.py create mode 100644 python3_anticaptcha/aioAntiCaptchaControl.py diff --git a/aio_test.py b/aio_test.py new file mode 100644 index 0000000..9929323 --- /dev/null +++ b/aio_test.py @@ -0,0 +1,6 @@ +from python3_anticaptcha import aioAntiCaptchaControl + +import time +print(aioAntiCaptchaControl.AntiCaptchaControl(anticaptcha_key='ae23fffcfaa29b170e3843e3a486ef19').get_balance()) + +print(aioAntiCaptchaControl.AntiCaptchaControl(anticaptcha_key='ae23fffcfaa29b170e3843e3a486ef19').complaint_on_result(reported_id=-7)) \ No newline at end of file diff --git a/python3_anticaptcha/aioAntiCaptchaControl.py b/python3_anticaptcha/aioAntiCaptchaControl.py new file mode 100644 index 0000000..afc6e57 --- /dev/null +++ b/python3_anticaptcha/aioAntiCaptchaControl.py @@ -0,0 +1,49 @@ +import aiohttp +import asyncio + +from .config import get_balance_url, incorrect_captcha_url + + +class AntiCaptchaControl: + def __init__(self, anticaptcha_key): + self.ANTICAPTCHA_KEY = anticaptcha_key + + def get_balance(self): + ''' + Получение баланса аккаунта + :return: Возвращает актуальный баланс + ''' + loop = asyncio.get_event_loop() + server_answer = loop.run_until_complete(self.aio_get_balance()) + loop.close() + + return server_answer + + async def aio_get_balance(self): + async with aiohttp.ClientSession() as session: + async with session.post(get_balance_url, json={'clientKey': self.ANTICAPTCHA_KEY}) as resp: + return await resp.json() + + def complaint_on_result(self, reported_id): + ''' + Позволяет отправить жалобу на неправильно решённую капчу. + :param reported_id: Отправляете ID капчи на которую нужно пожаловаться + :return: Возвращает True/False, в зависимости от результата + ''' + loop = asyncio.get_event_loop() + server_answer = loop.run_until_complete(self.aio_complaint_on_result(reported_id)) + loop.close() + + if server_answer['errorId'] == 0: + return True + else: + return False + + + async def aio_complaint_on_result(self, reported_id): + payload = {'clientKey': self.ANTICAPTCHA_KEY, + 'taskId': reported_id, + } + async with aiohttp.ClientSession() as session: + async with session.post(incorrect_captcha_url, json=payload) as resp: + return await resp.json()