Skip to content

Commit f35454d

Browse files
author
Andrei
authored
Merge pull request #40 from AndreiDrang/main
0.9
2 parents 78f46a1 + 47dae23 commit f35454d

20 files changed

Lines changed: 660 additions & 32 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
paths:
77
- '.github/workflows/test.yml'
88
- 'src/**'
9+
- 'tests/**'
910
- 'Makefile'
1011
- 'requirements.test.txt'
1112
pull_request:
@@ -26,7 +27,7 @@ jobs:
2627
strategy:
2728
fail-fast: false
2829
matrix:
29-
python-version: ["3.8", "3.11"]
30+
python-version: ["3.11", ]
3031

3132
steps:
3233
- uses: actions/checkout@v3

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ upload:
2828

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

3636
doc: install
3737
cd docs/ && \

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from python3_capsolver import (
77
core,
88
akamai,
9+
binance,
10+
imperva,
911
gee_test,
1012
hcaptcha,
1113
recaptcha,

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ The library is intended for software developers and is used to work with the `Ca
3333
modules/aws-waf/example.rst
3434
modules/cyber-si-ara/example.rst
3535
modules/akamai/example.rst
36+
modules/imperva/example.rst
37+
modules/binance/example.rst
3638

3739
.. toctree::
3840
:maxdepth: 2

docs/modules/binance/example.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Binance
2+
=======
3+
4+
To import this module:
5+
6+
.. code-block:: python
7+
8+
from python3_capsolver.binance import Binance
9+
10+
11+
.. autoclass:: python3_capsolver.binance.Binance
12+
:members:

docs/modules/enum/info.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,15 @@ To import this module:
7171
.. autoclass:: python3_capsolver.core.enum.ImageToTextTaskTypeEnm
7272
:members:
7373
:undoc-members:
74+
75+
.. autoclass:: python3_capsolver.core.enum.AntiAkamaiTaskEnm
76+
:members:
77+
:undoc-members:
78+
79+
.. autoclass:: python3_capsolver.core.enum.AntiImpervaTaskEnm
80+
:members:
81+
:undoc-members:
82+
83+
.. autoclass:: python3_capsolver.core.enum.BinanceCaptchaTaskEnm
84+
:members:
85+
:undoc-members:

docs/modules/imperva/example.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Imperva
2+
=======
3+
4+
To import this module:
5+
6+
.. code-block:: python
7+
8+
from python3_capsolver.imperva import Imperva
9+
10+
11+
.. autoclass:: python3_capsolver.imperva.Imperva
12+
:members:

docs/modules/serializer/info.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@ To import this module:
2828
:undoc-members:
2929

3030
.. autopydantic_model:: python3_capsolver.core.serializer.AntiAkamaiWebTaskSer
31+
:members:
32+
:undoc-members:
33+
34+
.. autopydantic_model:: python3_capsolver.core.serializer.AntiImpervaTaskSer
35+
:members:
36+
:undoc-members:
37+
38+
.. autopydantic_model:: python3_capsolver.core.serializer.BinanceCaptchaTaskSer
3139
:members:
3240
:undoc-members:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8"
1+
__version__ = "0.9"

src/python3_capsolver/binance.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
from typing import Union
2+
3+
from python3_capsolver.core.base import BaseCaptcha
4+
from python3_capsolver.core.enum import BinanceCaptchaTaskEnm
5+
from python3_capsolver.core.serializer import CaptchaResponseSer, BinanceCaptchaTaskSer
6+
7+
8+
class Binance(BaseCaptcha):
9+
"""
10+
The class is used to work with Capsolver Imperva method.
11+
12+
Args:
13+
api_key: Capsolver API key
14+
captcha_type: Captcha type name, like ``AntiImpervaTask`` and etc.
15+
websiteUrl: The website url
16+
userAgent: Browser userAgent
17+
18+
Examples:
19+
>>> Binance(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
20+
... captcha_type="BinanceCaptchaTask",
21+
... websiteURL="https://www.milanuncios.com/",
22+
... websiteKey="login",
23+
... validateId="3621a4fef82f4ab4a00e8b07465761c5",
24+
... ).captcha_handler()
25+
CaptchaResponseSer(errorId=0,
26+
errorCode=None,
27+
errorDescription=None,
28+
taskId='73bdcd28-6c77-4414-8....',
29+
status=<ResponseStatusEnm.Ready: 'ready'>,
30+
solution={'token': '90F9EAF...'}
31+
)
32+
33+
>>> Binance(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
34+
... captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask,
35+
... websiteURL="https://www.milanuncios.com/",
36+
... websiteKey="login",
37+
... validateId="3621a4fef82f4ab4a00e8b07465761c5",
38+
... ).captcha_handler()
39+
CaptchaResponseSer(errorId=0,
40+
errorCode=None,
41+
errorDescription=None,
42+
taskId='73bdcd28-6c77-4414-8....',
43+
status=<ResponseStatusEnm.Ready: 'ready'>,
44+
solution={'token': '90F9EAF...'}
45+
)
46+
47+
>>> await Binance(api_key="CAI-BA9650D2B9C2786B21120D512702E010",
48+
... captcha_type=BinanceCaptchaTaskEnm.BinanceCaptchaTask,
49+
... websiteURL="https://www.milanuncios.com/",
50+
... websiteKey="login",
51+
... validateId="3621a4fef82f4ab4a00e8b07465761c5",
52+
... ).aio_captcha_handler()
53+
CaptchaResponseSer(errorId=0,
54+
errorCode=None,
55+
errorDescription=None,
56+
taskId='73bdcd28-6c77-4414-8....',
57+
status=<ResponseStatusEnm.Ready: 'ready'>,
58+
solution={'token': '90F9EAF...'}
59+
)
60+
61+
Returns:
62+
CaptchaResponseSer model with full server response
63+
64+
Notes:
65+
https://docs.capsolver.com/guide/captcha/BnCaptcha.html
66+
"""
67+
68+
def __init__(
69+
self,
70+
captcha_type: Union[BinanceCaptchaTaskEnm, str],
71+
websiteURL: str,
72+
validateId: str,
73+
websiteKey: str = "login",
74+
*args,
75+
**kwargs,
76+
):
77+
super().__init__(*args, **kwargs)
78+
79+
if captcha_type == BinanceCaptchaTaskEnm.BinanceCaptchaTask:
80+
self.task_params = BinanceCaptchaTaskSer(**locals()).dict()
81+
else:
82+
raise ValueError(
83+
f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`,
84+
available - {BinanceCaptchaTaskEnm.list_values()}"""
85+
)
86+
87+
for key in kwargs:
88+
self.task_params.update({key: kwargs[key]})
89+
90+
def captcha_handler(self) -> CaptchaResponseSer:
91+
"""
92+
Sync solving method
93+
94+
Returns:
95+
CaptchaResponseSer model with full service response
96+
97+
Notes:
98+
Check class docstring for more info
99+
"""
100+
return self._processing_captcha(create_params=self.task_params)
101+
102+
async def aio_captcha_handler(self) -> CaptchaResponseSer:
103+
"""
104+
Async method for captcha solving
105+
106+
Returns:
107+
CaptchaResponseSer model with full service response
108+
109+
Notes:
110+
Check class docstring for more info
111+
"""
112+
return await self._aio_processing_captcha(create_params=self.task_params)

0 commit comments

Comments
 (0)