Skip to content

Commit 0d5abfc

Browse files
author
Andrei
committed
refactor
1 parent be89b20 commit 0d5abfc

4 files changed

Lines changed: 16 additions & 32 deletions

File tree

src/python3_capsolver/control.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,42 @@
11
from python3_capsolver.core.base import BaseCaptcha
22
from python3_capsolver.core.enum import EndpointPostfixEnm
3-
from python3_capsolver.core.config import REQUEST_URL
43
from python3_capsolver.core.serializer import PostRequestSer, ControlResponseSer
54

65

7-
class BaseControl(BaseCaptcha):
6+
class Control(BaseCaptcha):
87
"""
8+
The class is used to work with Capsolver control methods.
9+
910
Args:
1011
api_key: Capsolver API key
11-
sleep_time: The waiting time between requests to get the result of the Captcha
12-
request_url: API address for sending requests
12+
13+
Notes:
14+
https://docs.capsolver.com/guide/api-getbalance.html
1315
"""
1416

1517
serializer = PostRequestSer
1618

1719
def __init__(
1820
self,
19-
api_key: str,
20-
sleep_time: int = 10,
21-
request_url: str = REQUEST_URL,
21+
*args,
22+
**kwargs,
2223
):
2324

24-
super().__init__(
25-
api_key=api_key, sleep_time=sleep_time, request_url=request_url, captcha_type="CaptchaTypeEnm.Control"
26-
)
27-
28-
29-
class Control(BaseControl):
30-
"""
31-
The class is used to work with Capsolver control methods.
32-
33-
Notes:
34-
https://captchaai.atlassian.net/wiki/spaces/CAPTCHAAI/pages/426042/API+Methods
35-
"""
25+
super().__init__(*args, **kwargs)
3626

3727
def get_balance(self) -> ControlResponseSer:
3828
"""
3929
Synchronous method to view the balance
4030
4131
Examples:
42-
>>> Control(api_key="CAI-12345").get_balance()
43-
ResponseSer(balance=1.0 errorId=False errorCode=None errorDescription=None)
32+
>>> Control(api_key="CAI-1324...").get_balance()
33+
ControlResponseSer(errorId=0 errorCode=None errorDescription=None balance=150.9085)
4434
4535
Returns:
4636
ResponseSer model with full server response
4737
4838
Notes:
49-
https://captchaai.atlassian.net/wiki/spaces/CAPTCHAAI/pages/426080/getBalance+retrieve+account+balance
39+
https://docs.capsolver.com/guide/api-getbalance.html
5040
"""
5141
self._prepare_create_task_payload(serializer=self.serializer)
5242
return ControlResponseSer(
@@ -60,14 +50,14 @@ async def aio_get_balance(self) -> ControlResponseSer:
6050
Asynchronous method to view the balance
6151
6252
Examples:
63-
>>> await Control(api_key="CAI-12345").aio_get_balance()
64-
ResponseSer(balance=1.0 errorId=False errorCode=None errorDescription=None)
53+
>>> await Control(api_key="CAI-1324...").aio_get_balance()
54+
ControlResponseSer(errorId=0 errorCode=None errorDescription=None balance=150.9085)
6555
6656
Returns:
6757
ResponseSer model with full server response
6858
6959
Notes:
70-
https://captchaai.atlassian.net/wiki/spaces/CAPTCHAAI/pages/426080/getBalance+retrieve+account+balance
60+
https://docs.capsolver.com/guide/api-getbalance.html
7161
"""
7262
self._prepare_create_task_payload(serializer=self.serializer)
7363
return ControlResponseSer(

src/python3_capsolver/core/base.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@ def _create_task(self, url_postfix: str = EndpointPostfixEnm.CREATE_TASK.value)
102102
Function send SYNC request to service and wait for result
103103
"""
104104
try:
105-
print(self.task_payload.dict(exclude_none=True))
106105
resp = self.__session.post(
107106
parse.urljoin(self.__request_url, url_postfix), json=self.task_payload.dict(exclude_none=True)
108107
)
109-
print(resp.status_code)
110-
print(resp.json())
111108
if resp.status_code in VALID_STATUS_CODES:
112109
return resp.json()
113110
else:

src/python3_capsolver/core/enum.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@ class CaptchaTypeEnmXXX(str, MyEnum):
5252
https://captchaai.atlassian.net/wiki/spaces/CAPTCHAAI/pages/393295
5353
"""
5454

55-
Control = "Control" # custom captcha type
5655
ImageToTextTask = "ImageToTextTask"
5756
# HCaptcha
5857
HCaptchaClassification = "HCaptchaClassification"
5958
# FunCaptcha
6059
FunCaptchaClassification = "FunCaptchaClassification"
6160
# Other types
62-
DatadomeSliderTask = "DatadomeSliderTask"
6361
AntiKasadaTask = "AntiKasadaTask"
6462
AntiAkamaiBMPTask = "AntiAkamaiBMPTask"
6563

src/python3_capsolver/core/serializer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
class PostRequestSer(BaseModel):
1414
clientKey: str = Field(..., description="Client account key, can be found in user account")
15+
task: dict = Field(None, description="Task object")
1516

1617

1718
class TaskSer(BaseModel):
1819
type: str = Field(..., description="Task type name", alias="captcha_type")
1920

2021

2122
class RequestCreateTaskSer(PostRequestSer):
22-
task: dict = Field(None, description="Task object")
2323
appId: str = Field(APP_ID, description="AppID", const=True)
2424

2525

@@ -50,7 +50,6 @@ class Config:
5050

5151
class ControlResponseSer(ResponseSer):
5252
balance: Optional[float] = Field(0, description="Account balance value in USD")
53-
packages: List = Field(None, description="Monthly Packages")
5453

5554

5655
"""

0 commit comments

Comments
 (0)