Skip to content

Commit 78f46a1

Browse files
author
Andrei
authored
Merge pull request #39 from AndreiDrang/main
0.8
2 parents 0698bbc + 21a787e commit 78f46a1

16 files changed

Lines changed: 272 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
python-version: ["3.8", "3.9", "3.10", "3.11"]
29+
python-version: ["3.8", "3.11"]
3030

3131
steps:
3232
- uses: actions/checkout@v3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ At the lowest price on the market, you may receive a variety of solutions, inclu
1010

1111
[![PyPI version](https://badge.fury.io/py/python3-capsolver.svg)](https://badge.fury.io/py/python3-capsolver)
1212
[![Python versions](https://img.shields.io/pypi/pyversions/python3-capsolver.svg?logo=python&logoColor=FBE072)](https://badge.fury.io/py/python3-capsolver)
13-
[![Downloads](https://pepy.tech/badge/python3-capsolver/month)](https://pepy.tech/project/python3-capsolver)
13+
[![Downloads](https://static.pepy.tech/badge/python3-capsolver/month)](https://pepy.tech/project/python3-capsolver)
1414

1515
[![Maintainability](https://api.codeclimate.com/v1/badges/3c30167b5fb37a0775ea/maintainability)](https://codeclimate.com/github/AndreiDrang/python3-capsolver/maintainability)
1616
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/323d4eda0fe1477bbea8fe8902b9e97e)](https://www.codacy.com/gh/AndreiDrang/python3-capsolver/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AndreiDrang/python3-capsolver&utm_campaign=Badge_Grade)

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from python3_capsolver import (
77
core,
8+
akamai,
89
gee_test,
910
hcaptcha,
1011
recaptcha,

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The library is intended for software developers and is used to work with the `Ca
3232
modules/cloudflare/example.rst
3333
modules/aws-waf/example.rst
3434
modules/cyber-si-ara/example.rst
35+
modules/akamai/example.rst
3536

3637
.. toctree::
3738
:maxdepth: 2

docs/modules/akamai/example.rst

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

docs/modules/serializer/info.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ To import this module:
1616
.. autopydantic_model:: python3_capsolver.core.serializer.WebsiteDataOptionsSer
1717
:members:
1818
:undoc-members:
19+
20+
21+
.. autopydantic_model:: python3_capsolver.core.serializer.CyberSiAraSer
22+
:members:
23+
:undoc-members:
24+
25+
26+
.. autopydantic_model:: python3_capsolver.core.serializer.AntiAkamaiBMPTaskSer
27+
:members:
28+
:undoc-members:
29+
30+
.. autopydantic_model:: python3_capsolver.core.serializer.AntiAkamaiWebTaskSer
31+
:members:
32+
:undoc-members:

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pallets_sphinx_themes==2.*
22
myst-parser==2.0.*
3-
autodoc_pydantic==1.9.*
3+
autodoc_pydantic==1.9.0

requirements.style.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# codestyle
22
isort==5.*
3-
black==23.7.0
3+
black==23.9.1
44
autoflake==2.*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.7.1"
1+
__version__ = "0.8"

src/python3_capsolver/akamai.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
from typing import Union
2+
3+
from python3_capsolver.core.base import BaseCaptcha
4+
from python3_capsolver.core.enum import AntiAkamaiTaskEnm, EndpointPostfixEnm
5+
from python3_capsolver.core.serializer import (
6+
PostRequestSer,
7+
CaptchaResponseSer,
8+
AntiAkamaiBMPTaskSer,
9+
AntiAkamaiWebTaskSer,
10+
)
11+
12+
13+
class Akamai(BaseCaptcha):
14+
"""
15+
The class is used to work with Capsolver AntiAkamai methods.
16+
17+
Args:
18+
api_key: Capsolver API key
19+
captcha_type: Captcha type name, like ``AntiAkamaiBMPTask`` and etc.
20+
packageName: Package name of AkamaiBMP mobile APP
21+
version: AKAMAI BMP Version number, default is: 3.2.6 , max support 3.3.1
22+
23+
Examples:
24+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
25+
... captcha_type="AntiAkamaiBMPTask",
26+
... packageName="de.zalando.iphone",
27+
... country="US",
28+
... deviceId="90F9EAF5-D6E5-4E30-BC8B-B7780AD02600",
29+
... deviceName="iPhone14,2/16.0.2",
30+
... count=10,
31+
... ).captcha_handler()
32+
CaptchaResponseSer(errorId=0,
33+
errorCode=None,
34+
errorDescription=None,
35+
taskId='73bdcd28-6c77-4414-8....',
36+
status=<ResponseStatusEnm.Ready: 'ready'>,
37+
solution={'deviceId': '90F9EAF...'}
38+
)
39+
40+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
41+
... captcha_type="AntiAkamaiWebTask",
42+
... url="https://www.xxxx.com/nMRH2/aYJ/PQ4b/32/0peDlm/b9f5NJcXf7tiYE/OE9CMGI1/Nzsn/bCVKCnA",
43+
... abck="14164862507BD4......",
44+
... bmsz="4E3C....33",
45+
... userAgent="Mozilla/5.0 (Wi....",
46+
... ).captcha_handler()
47+
CaptchaResponseSer(errorId=0,
48+
errorCode=None,
49+
errorDescription=None,
50+
taskId='73bdcd28-6c77-4414-8....',
51+
status=<ResponseStatusEnm.Ready: 'ready'>,
52+
solution={'sensorData': '2;3159346;4338233...'}
53+
)
54+
55+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
56+
... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiBMPTask,
57+
... ).captcha_handler()
58+
CaptchaResponseSer(errorId=0,
59+
errorCode=None,
60+
errorDescription=None,
61+
taskId='73bdcd28-6c77-4414-8....',
62+
status=<ResponseStatusEnm.Ready: 'ready'>,
63+
solution={'deviceId': '6DKFOD0...'}
64+
)
65+
66+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
67+
... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiWebTask,
68+
... url="https://www.xxxx.com/nMRH2/aYJ/PQ4b/32/0peDlm/b9f5NJcXf7tiYE/OE9CMGI1/Nzsn/bCVKCnA",
69+
... ).captcha_handler()
70+
CaptchaResponseSer(errorId=0,
71+
errorCode=None,
72+
errorDescription=None,
73+
taskId='73bdcd28-6c77-4414-8....',
74+
status=<ResponseStatusEnm.Ready: 'ready'>,
75+
solution={'sensorData': '2;3159346;4338233...'}
76+
)
77+
78+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
79+
... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiBMPTask,
80+
... **{
81+
... "version": "3.2.6",
82+
... "deviceId": "90F9EAF5-D6E5-4E30-BC8B-B7780AD02600",
83+
... "deviceName": "iPhone14,2/16.0.2",
84+
... "count": 10,
85+
... },
86+
... ).captcha_handler()
87+
CaptchaResponseSer(errorId=0,
88+
errorCode=None,
89+
errorDescription=None,
90+
taskId="87f149f4-1c....",
91+
status=<ResponseStatusEnm.Ready: 'ready'>,
92+
solution={'deviceId': '90F9EAF...'}
93+
)
94+
95+
>>> await Akamai(api_key="CAI-BA9650D2B9C2786B21120D512702E010",
96+
... captcha_type="AntiAkamaiBMPTask",
97+
... packageName="de.zalando.iphone",
98+
... country="US",
99+
... deviceId="90F9EAF5-D6E5-4E30-BC8B-B7780AD02600",
100+
... deviceName="iPhone14,2/16.0.2",
101+
... count=10,
102+
... ).aio_captcha_handler()
103+
CaptchaResponseSer(errorId=0,
104+
errorCode=None,
105+
errorDescription=None,
106+
taskId='73bdcd28-6c77-4414-8....',
107+
status=<ResponseStatusEnm.Ready: 'ready'>,
108+
solution={'deviceId': '90F9EAF...'}
109+
)
110+
111+
>>> await Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
112+
... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiWebTask,
113+
... url="https://www.xxxx.com/nMRH2/aYJ/PQ4b/32/0peDlm/b9f5NJcXf7tiYE/OE9CMGI1/Nzsn/bCVKCnA",
114+
... ).aio_captcha_handler()
115+
CaptchaResponseSer(errorId=0,
116+
errorCode=None,
117+
errorDescription=None,
118+
taskId='73bdcd28-6c77-4414-8....',
119+
status=<ResponseStatusEnm.Ready: 'ready'>,
120+
solution={'sensorData': '2;3159346;4338233...'}
121+
)
122+
123+
Returns:
124+
CaptchaResponseSer model with full server response
125+
126+
Notes:
127+
https://docs.capsolver.com/guide/antibots/akamaibmp.html
128+
https://docs.capsolver.com/guide/antibots/akamaiweb.html
129+
"""
130+
131+
def __init__(
132+
self,
133+
captcha_type: Union[AntiAkamaiTaskEnm, str],
134+
packageName: str = "de.zalando.iphone",
135+
version: str = "3.2.6",
136+
country: str = "US",
137+
url: str = None,
138+
*args,
139+
**kwargs,
140+
):
141+
super().__init__(*args, **kwargs)
142+
self.__serializer = PostRequestSer
143+
self.__url_postfix = None
144+
145+
if captcha_type == AntiAkamaiTaskEnm.AntiAkamaiBMPTask:
146+
self.task_params = AntiAkamaiBMPTaskSer(**locals()).dict()
147+
self.__url_postfix = EndpointPostfixEnm.AKAMAI_BMP_INVOKE.value
148+
elif captcha_type == AntiAkamaiTaskEnm.AntiAkamaiWebTask:
149+
self.task_params = AntiAkamaiWebTaskSer(**locals()).dict()
150+
self.__url_postfix = EndpointPostfixEnm.AKAMAI_WEB_INVOKE.value
151+
else:
152+
raise ValueError(
153+
f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`,
154+
available - {AntiAkamaiTaskEnm.list_values()}"""
155+
)
156+
157+
for key in kwargs:
158+
self.task_params.update({key: kwargs[key]})
159+
160+
def captcha_handler(self) -> CaptchaResponseSer:
161+
"""
162+
Sync solving method
163+
164+
Returns:
165+
CaptchaResponseSer model with full service response
166+
167+
Notes:
168+
Check class docstring for more info
169+
"""
170+
self._prepare_create_task_payload(serializer=self.__serializer, create_params=self.task_params)
171+
return CaptchaResponseSer(
172+
**self._create_task(
173+
url_postfix=self.__url_postfix,
174+
)
175+
)
176+
177+
async def aio_captcha_handler(self) -> CaptchaResponseSer:
178+
"""
179+
Async method for captcha solving
180+
181+
Returns:
182+
CaptchaResponseSer model with full service response
183+
184+
Notes:
185+
Check class docstring for more info
186+
"""
187+
self._prepare_create_task_payload(serializer=self.__serializer, create_params=self.task_params)
188+
return CaptchaResponseSer(
189+
**await self._aio_create_task(
190+
url_postfix=self.__url_postfix,
191+
)
192+
)

0 commit comments

Comments
 (0)