Skip to content

Commit

Permalink
added binance
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Sep 12, 2023
1 parent 2be7b2e commit f180527
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ upload:

tests: install
coverage run --rcfile=.coveragerc -m pytest -vv --showlocals --pastebin=all \
tests && \
tests/test_binance.py && \
coverage report --precision=3 --sort=cover --skip-empty --show-missing && \
coverage html --precision=3 --skip-empty -d src/coverage/html/ && \
coverage xml -o src/coverage/coverage.xml
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from python3_capsolver import (
core,
akamai,
binance,
imperva,
gee_test,
hcaptcha,
recaptcha,
mt_captcha,
fun_captcha,
image_to_text,
datadome_slider,
imperva,
)
from python3_capsolver.__version__ import __version__

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The library is intended for software developers and is used to work with the `Ca
modules/cyber-si-ara/example.rst
modules/akamai/example.rst
modules/imperva/example.rst
modules/binance/example.rst

.. toctree::
:maxdepth: 2
Expand Down
12 changes: 12 additions & 0 deletions docs/modules/binance/example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Binance
=======

To import this module:

.. code-block:: python
from python3_capsolver.binance import Binance
.. autoclass:: python3_capsolver.binance.Binance
:members:
4 changes: 4 additions & 0 deletions docs/modules/enum/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ To import this module:
.. autoclass:: python3_capsolver.core.enum.AntiImpervaTaskEnm
:members:
:undoc-members:

.. autoclass:: python3_capsolver.core.enum.BinanceCaptchaTaskEnm
:members:
:undoc-members:
4 changes: 4 additions & 0 deletions docs/modules/serializer/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ To import this module:
:undoc-members:

.. autopydantic_model:: python3_capsolver.core.serializer.AntiImpervaTaskSer
:members:
:undoc-members:

.. autopydantic_model:: python3_capsolver.core.serializer.BinanceCaptchaTaskSer
:members:
:undoc-members:
121 changes: 121 additions & 0 deletions src/python3_capsolver/binance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from typing import Union

from python3_capsolver.core.base import BaseCaptcha
from python3_capsolver.core.enum import BinanceCaptchaTaskEnm
from python3_capsolver.core.serializer import CaptchaResponseSer, BinanceCaptchaTaskSer


class Binance(BaseCaptcha):
"""
The class is used to work with Capsolver Imperva method.
Args:
api_key: Capsolver API key
captcha_type: Captcha type name, like ``AntiImpervaTask`` and etc.
websiteUrl: The website url
userAgent: Browser userAgent
Examples:
>>> Imperva(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
... captcha_type="AntiImpervaTask",
... websiteUrl="https://www.milanuncios.com/",
... userAgent="Mozilla/5.0 (Windows ....",
... proxy="socks5:98.181.137.83:4145",
... utmvc=True,
... reese84=True,
... reeseScriptUrl="https://www.milanuncios.com/librarym.js",
... ).captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'token': '90F9EAF...'}
)
>>> Imperva(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
... captcha_type=AntiImpervaTaskEnm.AntiImpervaTask,
... websiteUrl="https://www.milanuncios.com/",
... userAgent="Mozilla/5.0 (Windows ....",
... proxy="socks5:98.181.137.83:4145",
... utmvc=True,
... reese84=True,
... reeseScriptUrl="https://www.milanuncios.com/librarym.js",
... ).captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'token': '90F9EAF...'}
)
>>> await Imperva(api_key="CAI-BA9650D2B9C2786B21120D512702E010",
... captcha_type=AntiImpervaTaskEnm.AntiImpervaTask,
... websiteUrl="https://www.milanuncios.com/",
... userAgent="Mozilla/5.0 (Windows ....",
... proxy="socks5:98.181.137.83:4145",
... utmvc=True,
... reese84=True,
... reeseScriptUrl="https://www.milanuncios.com/librarym.js",
... ).aio_captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'token': '90F9EAF...'}
)
Returns:
CaptchaResponseSer model with full server response
Notes:
https://docs.capsolver.com/guide/antibots/imperva.html
"""

def __init__(
self,
captcha_type: Union[BinanceCaptchaTaskEnm, str],
websiteURL: str,
validateId: str,
websiteKey: str = "login",
*args,
**kwargs,
):
super().__init__(*args, **kwargs)

if captcha_type == BinanceCaptchaTaskEnm.BinanceCaptchaTask:
self.task_params = BinanceCaptchaTaskSer(**locals()).dict()
else:
raise ValueError(
f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`,
available - {BinanceCaptchaTaskEnm.list_values()}"""
)

for key in kwargs:
self.task_params.update({key: kwargs[key]})

def captcha_handler(self) -> CaptchaResponseSer:
"""
Sync solving method
Returns:
CaptchaResponseSer model with full service response
Notes:
Check class docstring for more info
"""
return self._processing_captcha(create_params=self.task_params)

async def aio_captcha_handler(self) -> CaptchaResponseSer:
"""
Async method for captcha solving
Returns:
CaptchaResponseSer model with full service response
Notes:
Check class docstring for more info
"""
return await self._aio_processing_captcha(create_params=self.task_params)
4 changes: 4 additions & 0 deletions src/python3_capsolver/core/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class AntiImpervaTaskEnm(str, MyEnum):
AntiImpervaTask = "AntiImpervaTask"


class BinanceCaptchaTaskEnm(str, MyEnum):
BinanceCaptchaTask = "BinanceCaptchaTask"


class ResponseStatusEnm(str, MyEnum):
"""
Enum store results `status` field variants
Expand Down
6 changes: 6 additions & 0 deletions src/python3_capsolver/core/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ class AntiImpervaTaskSer(TaskSer):
True, description="If cookie contains `incap_see_xxx`, `nlbi_xxx`, `visid_inap_xxx`, mean is true"
)
reese84: bool = Field(True, description="if cookie conains `reese84`, set it true")


class BinanceCaptchaTaskSer(TaskSer):
websiteURL: str = Field(..., description="Address of a webpage with Binance captcha")
websiteKey: str = Field("login", description="`bizId` always be `login`")
validateId: str = Field(..., description="`validateId` bncaptcha validateId field")
1 change: 1 addition & 0 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def run(self):
amazon_waf
akamai
imperva
binance
""",
python_requires=REQUIRES_PYTHON,
zip_safe=False,
Expand Down
46 changes: 46 additions & 0 deletions tests/test_binance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest

from tests.conftest import BaseTest
from python3_capsolver.binance import Binance
from python3_capsolver.core.enum import BinanceCaptchaTaskEnm


class TestBinanceBase(BaseTest):
def test_captcha_handler_exist(self):
assert "captcha_handler" in Binance.__dict__.keys()

def test_aio_captcha_handler_exist(self):
assert "aio_captcha_handler" in Binance.__dict__.keys()

def test_wrong_captcha_type(self):
with pytest.raises(ValueError):
Binance(
api_key=self.get_random_string(36),
captcha_type="test",
websiteURL=self.get_random_string(36),
validateId=self.get_random_string(36),
)

def test_no_captcha_type(self):
with pytest.raises(TypeError):
Binance(
api_key=self.get_random_string(36),
websiteURL=self.get_random_string(36),
validateId=self.get_random_string(36),
)

def test_no_websiteURL(self):
with pytest.raises(TypeError):
Binance(
api_key=self.get_random_string(36),
captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask,
validateId=self.get_random_string(36),
)

def test_no_validateId(self):
with pytest.raises(TypeError):
Binance(
api_key=self.get_random_string(36),
captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask,
websiteURL=self.get_random_string(36),
)

0 comments on commit f180527

Please sign in to comment.