Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.9 #40

Merged
merged 17 commits into from
Sep 12, 2023
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- '.github/workflows/test.yml'
- 'src/**'
- 'tests/**'
- 'Makefile'
- 'requirements.test.txt'
pull_request:
Expand All @@ -26,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.11"]
python-version: ["3.11", ]

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ upload:

tests: install
coverage run --rcfile=.coveragerc -m pytest -vv --showlocals --pastebin=all \
tests && \
tests/ && \
coverage report --precision=3 --sort=cover --skip-empty --show-missing && \
coverage html --precision=3 --skip-empty -d coverage/html/ && \
coverage xml -o coverage/coverage.xml
coverage html --precision=3 --skip-empty -d src/coverage/html/ && \
coverage xml -o src/coverage/coverage.xml

doc: install
cd docs/ && \
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from python3_capsolver import (
core,
akamai,
binance,
imperva,
gee_test,
hcaptcha,
recaptcha,
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The library is intended for software developers and is used to work with the `Ca
modules/aws-waf/example.rst
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:
12 changes: 12 additions & 0 deletions docs/modules/enum/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,15 @@ To import this module:
.. autoclass:: python3_capsolver.core.enum.ImageToTextTaskTypeEnm
:members:
:undoc-members:

.. autoclass:: python3_capsolver.core.enum.AntiAkamaiTaskEnm
:members:
:undoc-members:

.. autoclass:: python3_capsolver.core.enum.AntiImpervaTaskEnm
:members:
:undoc-members:

.. autoclass:: python3_capsolver.core.enum.BinanceCaptchaTaskEnm
:members:
:undoc-members:
12 changes: 12 additions & 0 deletions docs/modules/imperva/example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Imperva
=======

To import this module:

.. code-block:: python

from python3_capsolver.imperva import Imperva


.. autoclass:: python3_capsolver.imperva.Imperva
:members:
8 changes: 8 additions & 0 deletions docs/modules/serializer/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ To import this module:
:undoc-members:

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

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

.. autopydantic_model:: python3_capsolver.core.serializer.BinanceCaptchaTaskSer
:members:
:undoc-members:
2 changes: 1 addition & 1 deletion src/python3_capsolver/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8"
__version__ = "0.9"
112 changes: 112 additions & 0 deletions src/python3_capsolver/binance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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:
>>> Binance(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
... captcha_type="BinanceCaptchaTask",
... websiteURL="https://www.milanuncios.com/",
... websiteKey="login",
... validateId="3621a4fef82f4ab4a00e8b07465761c5",
... ).captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'token': '90F9EAF...'}
)

>>> Binance(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
... captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask,
... websiteURL="https://www.milanuncios.com/",
... websiteKey="login",
... validateId="3621a4fef82f4ab4a00e8b07465761c5",
... ).captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'token': '90F9EAF...'}
)

>>> await Binance(api_key="CAI-BA9650D2B9C2786B21120D512702E010",
... captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask,
... websiteURL="https://www.milanuncios.com/",
... websiteKey="login",
... validateId="3621a4fef82f4ab4a00e8b07465761c5",
... ).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/captcha/BnCaptcha.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)
24 changes: 9 additions & 15 deletions src/python3_capsolver/cloudflare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Union, Optional
from typing import Union, Optional

from python3_capsolver.core.base import BaseCaptcha
from python3_capsolver.core.enum import CloudflareTypeEnm
Expand All @@ -22,46 +22,42 @@ class Cloudflare(BaseCaptcha):
>>> Cloudflare(api_key="CAI-1324...",
... captcha_type=CloudflareTypeEnm.AntiCloudflareTask,
... websiteURL="https://bck.websiteurl.com/registry",
... websiteKey='4ac25d',
... proxy="socks5:158.120.100.23:334:user:pass",
... metadata={'type': 'turnstile', 'acton':'login', 'cdata': '0000-1111-2222-3333-example-cdata'}
... websiteKey='0x4AAAAAAABS7vwvV6VFfMcD',
... proxy="socks5:158.120.100.23:334:user:pass"
... ).captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'gRecaptchaResponse': '44795sds...'}
solution={'token': '44795sds...'}
)

>>> Cloudflare(api_key="CAI-1324...",
... captcha_type=CloudflareTypeEnm.AntiCloudflareTask,
... websiteURL="https://bck.websiteurl.com/registry",
... proxy="socks5:158.120.100.23:334:user:pass",
... metadata={'type': 'challenge'}
... html="<your challenge html source code>",
... proxy="socks5:158.120.100.23:334:user:pass"
... ).captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'gRecaptchaResponse': '44795sds...'}
solution={'token': '44795sds...'}
)

>>> await Cloudflare(api_key="CAI-1324...",
... captcha_type=CloudflareTypeEnm.AntiCloudflareTask,
... websiteURL="https://bck.websiteurl.com/registry",
... websiteKey='4ac25d',
... proxy="socks5:158.120.100.23:334:user:pass",
... metadata={'type': 'challenge', 'acton':'login', 'cdata': '0000-1111-2222-3333-example-cdata'}
... websiteKey='0x4AAAAAAABS7vwvV6VFfMcD',
... proxy="socks5:158.120.100.23:334:user:pass"
... ).aio_captcha_handler()
CaptchaResponseSer(errorId=0,
errorCode=None,
errorDescription=None,
taskId='73bdcd28-6c77-4414-8....',
status=<ResponseStatusEnm.Ready: 'ready'>,
solution={'gRecaptchaResponse': '44795sds...'}
solution={'token': '44795sds...'}
)

Returns:
Expand All @@ -76,9 +72,7 @@ def __init__(
self,
captcha_type: Union[CloudflareTypeEnm, str],
websiteURL: str,
metadata: Dict[str, str],
websiteKey: Optional[str] = None,
html: Optional[str] = None,
*args,
**kwargs,
):
Expand Down
12 changes: 10 additions & 2 deletions src/python3_capsolver/core/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""
The name of the Enum member
"""
return self._name_

Check warning on line 24 in src/python3_capsolver/core/enum.py

View check run for this annotation

Codecov / codecov/patch

src/python3_capsolver/core/enum.py#L24

Added line #L24 was not covered by tests

@DynamicClassAttribute
def value(self) -> str:
Expand All @@ -39,8 +39,8 @@
GET_BALANCE = "getBalance"
CREATE_TASK = "createTask"
GET_TASK_RESULT = "getTaskResult"
AKAMAI_BMP_INVOKE = "/akamaibmp/invoke"
AKAMAI_WEB_INVOKE = "/akamaiweb/invoke"
AKAMAI_BMP_INVOKE = "akamaibmp/invoke"
AKAMAI_WEB_INVOKE = "akamaiweb/invoke"


class ImageToTextTaskTypeEnm(str, MyEnum):
Expand Down Expand Up @@ -117,6 +117,14 @@
AntiAkamaiWebTask = "AntiAkamaiWebTask"


class AntiImpervaTaskEnm(str, MyEnum):
AntiImpervaTask = "AntiImpervaTask"


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


class ResponseStatusEnm(str, MyEnum):
"""
Enum store results `status` field variants
Expand Down
24 changes: 18 additions & 6 deletions src/python3_capsolver/core/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ class DatadomeSliderSer(TaskSer):


class CloudflareTurnstileSer(WebsiteDataOptionsSer):
metadata: dict = Field(..., description="Extra data")
html: Optional[str] = Field(
None, description="You can pass in the entire html source code for the challenge directly."
)
...


class CyberSiAraSer(WebsiteDataOptionsSer):
Expand All @@ -134,11 +131,26 @@ class CyberSiAraSer(WebsiteDataOptionsSer):
UserAgent: str = Field(..., description="Browser userAgent, you need submit your userAgent")


class AntiAkamaiBMPTaskSer(BaseModel):
class AntiAkamaiBMPTaskSer(TaskSer):
packageName: str = Field("de.zalando.iphone", description="Package name of AkamaiBMP mobile APP")
version: str = Field("3.2.6", description="AKAMAI BMP Version number")
country: str = Field("US", description="AKAMAI BMP country")


class AntiAkamaiWebTaskSer(BaseModel):
class AntiAkamaiWebTaskSer(TaskSer):
url: str = Field(..., description="Browser url address")


class AntiImpervaTaskSer(TaskSer):
websiteUrl: str = Field(..., description="The website url")
userAgent: str = Field(..., description="Browser userAgent")
utmvc: bool = Field(
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")
Loading
Loading