python-rucaptcha 6.1__0-py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ from typing import Union
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import CapyPuzzleEnm
5
+
6
+
7
+ class CapyPuzzle(BaseCaptcha):
8
+ def __init__(
9
+ self,
10
+ websiteURL: str,
11
+ websiteKey: str,
12
+ method: Union[str, CapyPuzzleEnm] = CapyPuzzleEnm.CapyTaskProxyless,
13
+ *args,
14
+ **kwargs,
15
+ ):
16
+ """
17
+ The class is used to work with CapyPuzzle.
18
+
19
+ Args:
20
+ rucaptcha_key: User API key
21
+ websiteURL: Full URL of the captcha page
22
+ websiteKey: The value of the `captchakey` parameter you found in the code of the page
23
+ method: Captcha type
24
+
25
+ Examples:
26
+ >>> CapyPuzzle(rucaptcha_key="aa9011f31111181111168611f1151122",
27
+ ... websiteKey="PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w",
28
+ ... websiteURL="https://www.capy.me/account/register/",
29
+ ... method=CapyPuzzleEnm.CapyTaskProxyless.value,
30
+ ... api_server="https://jp.api.capy.me/",
31
+ ... version="puzzle",
32
+ ... ).captcha_handler()
33
+ {
34
+ "errorId":0,
35
+ "status":"ready",
36
+ "solution":{
37
+ "captchakey":"PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v",
38
+ "challengekey":"qHAPtn68KTnXFM8VQ3mtYRtmy3cSKuHJ",
39
+ "answer":"0xax8ex0xax84x0xkx7qx0xux7gx0xx42x0x3ox42x0x3ox4cx",
40
+ "respKey":""
41
+ },
42
+ "cost":"0.00299",
43
+ "ip":"1.2.3.4",
44
+ "createTime":1692863536,
45
+ "endTime":1692863556,
46
+ "solveCount":1,
47
+ "taskId":75190409731
48
+ }
49
+
50
+ >>> CapyPuzzle(rucaptcha_key="aa9011f31111181111168611f1151122",
51
+ ... websiteKey="PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w",
52
+ ... websiteURL="https://www.capy.me/account/register/",
53
+ ... method=CapyPuzzleEnm.CapyTaskProxyless.value,
54
+ ... api_server="https://jp.api.capy.me/",
55
+ ... version="avatar",
56
+ ... ).captcha_handler()
57
+ {
58
+ "errorId":0,
59
+ "status":"ready",
60
+ "solution":{
61
+ "captchakey":"PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v",
62
+ "challengekey":"qHAPtn68KTnXFM8VQ3mtYRtmy3cSKuHJ",
63
+ "answer":"0xax8ex0xax84x0xkx7qx0xux7gx0xx42x0x3ox42x0x3ox4cx",
64
+ "respKey":""
65
+ },
66
+ "cost":"0.00299",
67
+ "ip":"1.2.3.4",
68
+ "createTime":1692863536,
69
+ "endTime":1692863556,
70
+ "solveCount":1,
71
+ "taskId":75190409731
72
+ }
73
+
74
+ >>> CapyPuzzle(rucaptcha_key="aa9011f31111181111168611f1151122",
75
+ ... websiteKey="PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w",
76
+ ... websiteURL="https://www.capy.me/account/register/",
77
+ ... method="CapyTaskProxyless",
78
+ ... api_server="https://jp.api.capy.me/",
79
+ ... version="puzzle",
80
+ ... ).captcha_handler()
81
+ {
82
+ "errorId":0,
83
+ "status":"ready",
84
+ "solution":{
85
+ "captchakey":"PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v",
86
+ "challengekey":"qHAPtn68KTnXFM8VQ3mtYRtmy3cSKuHJ",
87
+ "answer":"0xax8ex0xax84x0xkx7qx0xux7gx0xx42x0x3ox42x0x3ox4cx",
88
+ "respKey":""
89
+ },
90
+ "cost":"0.00299",
91
+ "ip":"1.2.3.4",
92
+ "createTime":1692863536,
93
+ "endTime":1692863556,
94
+ "solveCount":1,
95
+ "taskId":75190409731
96
+ }
97
+
98
+ Returns:
99
+ Dict with full server response
100
+
101
+ Notes:
102
+ https://rucaptcha.com/api-docs/capy-puzzle-captcha
103
+ """
104
+ super().__init__(method=method, *args, **kwargs)
105
+
106
+ self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})
107
+
108
+ # check user params
109
+ if method not in CapyPuzzleEnm.list_values():
110
+ raise ValueError(f"Invalid method parameter set, available - {CapyPuzzleEnm.list_values()}")
111
+
112
+ def captcha_handler(self, **kwargs) -> dict:
113
+ """
114
+ Sync solving method
115
+
116
+ Args:
117
+ kwargs: additional params for `requests` library
118
+
119
+ Returns:
120
+ Dict with full server response
121
+
122
+ Notes:
123
+ Check class docstirng for more info
124
+ """
125
+
126
+ return self._processing_response(**kwargs)
127
+
128
+ async def aio_captcha_handler(self) -> dict:
129
+ """
130
+ Async solving method
131
+
132
+ Returns:
133
+ Dict with full server response
134
+
135
+ Notes:
136
+ Check class docstirng for more info
137
+ """
138
+ return await self._aio_processing_response()
@@ -0,0 +1,174 @@
1
+ from .core.base import BaseCaptcha
2
+ from .core.enums import ControlEnm
3
+ from .core.result_handler import get_sync_result, get_async_result
4
+
5
+
6
+ class Control(BaseCaptcha):
7
+ def __init__(
8
+ self,
9
+ *args,
10
+ **kwargs,
11
+ ):
12
+ """
13
+ The class is used to work with RuCaptcha control methods.
14
+
15
+ Args:
16
+ action: Control action type
17
+
18
+ Examples:
19
+ >>> Control(rucaptcha_key="aa9.....").getBalance()
20
+ {
21
+ 'balance': 1593.4479
22
+ }
23
+
24
+ >>> await Control(rucaptcha_key="aa9.....").aio_getBalance()
25
+ {
26
+ 'balance': 1593.4479
27
+ }
28
+
29
+ >>> Control(rucaptcha_key="aa9.....").reportCorrect(id=75188571838)
30
+ {
31
+ 'errorId': 0,
32
+ 'status': 'success'
33
+ }
34
+
35
+ >>> await Control(rucaptcha_key="aa9.....").aio_reportCorrect(id=75188571838)
36
+ {
37
+ 'errorId': 0,
38
+ 'status': 'success'
39
+ }
40
+
41
+ >>> Control(rucaptcha_key="aa9.....").reportIncorrect(id=75188571838)
42
+ {
43
+ 'errorId': 0,
44
+ 'status': 'success'
45
+ }
46
+
47
+ >>> await Control(rucaptcha_key="aa9.....").aio_reportIncorrect(id=75188571838)
48
+ {
49
+ 'errorId': 0,
50
+ 'status': 'success'
51
+ }
52
+
53
+ Returns:
54
+ Dict with full server response
55
+
56
+ Notes:
57
+ https://rucaptcha.com/api-docs/get-balance
58
+ https://rucaptcha.com/api-docs/report-correct
59
+ https://rucaptcha.com/api-docs/report-incorrect
60
+ """
61
+
62
+ super().__init__(method=ControlEnm.control, *args, **kwargs)
63
+
64
+ def reportCorrect(self, id: int) -> dict:
65
+ """
66
+ reportCorrect method
67
+
68
+ Args:
69
+ id: Captcha task ID
70
+
71
+ Returns:
72
+ Dict with full server response
73
+
74
+ Notes:
75
+ https://2captcha.com/api-docs/report-correct
76
+ """
77
+ self.get_task_payload.taskId = id
78
+ return get_sync_result(
79
+ get_payload=self.get_task_payload,
80
+ sleep_time=self.params.sleep_time,
81
+ url_response=f"https://api.{self.params.service_type}.com/reportCorrect",
82
+ )
83
+
84
+ async def aio_reportCorrect(self, id: int) -> dict:
85
+ """
86
+ Captcha results report
87
+
88
+ Args:
89
+ id: Captcha task ID
90
+
91
+ Returns:
92
+ Dict with full server response
93
+
94
+ Notes:
95
+ https://2captcha.com/api-docs/report-correct
96
+ """
97
+ self.get_task_payload.taskId = id
98
+ return await get_async_result(
99
+ get_payload=self.get_task_payload,
100
+ sleep_time=self.params.sleep_time,
101
+ url_response=f"https://api.{self.params.service_type}.com/reportCorrect",
102
+ )
103
+
104
+ def reportIncorrect(self, id: int) -> dict:
105
+ """
106
+ reportCorrect method
107
+
108
+ Args:
109
+ id: Captcha task ID
110
+
111
+ Returns:
112
+ Dict with full server response
113
+
114
+ Notes:
115
+ https://2captcha.com/api-docs/report-incorrect
116
+ """
117
+ self.get_task_payload.taskId = id
118
+ return get_sync_result(
119
+ get_payload=self.get_task_payload,
120
+ sleep_time=self.params.sleep_time,
121
+ url_response=f"https://api.{self.params.service_type}.com/reportIncorrect",
122
+ )
123
+
124
+ async def aio_reportIncorrect(self, id: int) -> dict:
125
+ """
126
+ Captcha results report
127
+
128
+ Args:
129
+ id: Captcha task ID
130
+
131
+ Returns:
132
+ Dict with full server response
133
+
134
+ Notes:
135
+ https://2captcha.com/api-docs/report-incorrect
136
+ """
137
+ self.get_task_payload.taskId = id
138
+ return await get_async_result(
139
+ get_payload=self.get_task_payload,
140
+ sleep_time=self.params.sleep_time,
141
+ url_response=f"https://api.{self.params.service_type}.com/reportIncorrect",
142
+ )
143
+
144
+ def getBalance(self) -> dict:
145
+ """
146
+ GetBalance method
147
+
148
+ Returns:
149
+ Dict with full server response
150
+
151
+ Notes:
152
+ Check class docstirng for more info
153
+ """
154
+ return get_sync_result(
155
+ get_payload=self.get_task_payload,
156
+ sleep_time=self.params.sleep_time,
157
+ url_response=f"https://api.{self.params.service_type}.com/getBalance",
158
+ )
159
+
160
+ async def aio_getBalance(self) -> dict:
161
+ """
162
+ Async GetBalance method
163
+
164
+ Returns:
165
+ Dict with full server response
166
+
167
+ Notes:
168
+ Check class docstirng for more info
169
+ """
170
+ return get_sync_result(
171
+ get_payload=self.get_task_payload,
172
+ sleep_time=self.params.sleep_time,
173
+ url_response=f"https://api.{self.params.service_type}.com/getBalance",
174
+ )
@@ -0,0 +1,295 @@
1
+ import shutil
2
+ import logging
3
+ from typing import Union, Optional
4
+
5
+ from .core.base import BaseCaptcha
6
+ from .core.enums import SaveFormatsEnm, CoordinatesCaptchaEnm
7
+
8
+
9
+ class CoordinatesCaptcha(BaseCaptcha):
10
+ def __init__(
11
+ self,
12
+ comment: str = "Draw Coordinates",
13
+ save_format: Union[str, SaveFormatsEnm] = SaveFormatsEnm.TEMP,
14
+ img_clearing: bool = True,
15
+ img_path: str = "PythonRuCaptchaBoundingBox",
16
+ *args,
17
+ **kwargs,
18
+ ):
19
+ """
20
+ The class is used to work with Bounding Box.
21
+
22
+ Args:
23
+ rucaptcha_key: User API key
24
+ save_format: The format in which the image will be saved, or as a temporary file - 'temp',
25
+ or as a regular image to a folder created by the library - 'const'.
26
+ img_clearing: True - delete file after solution, False - don't delete file after solution
27
+ img_path: Folder to save captcha images
28
+ kwargs: Additional not required params for this captcha type
29
+
30
+ Examples:
31
+ >>> CoordinatesCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
32
+ ... ).captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
33
+ {
34
+ "errorId":0,
35
+ "status":"ready",
36
+ "solution":{
37
+ "coordinates":[
38
+ {
39
+ "x": 358,
40
+ "y": 268
41
+ }
42
+ ],
43
+ },
44
+ "cost":0.033,
45
+ "ip":"46.53.241.91",
46
+ "createTime":1696730723,
47
+ "endTime":1696730723,
48
+ "solveCount":1,
49
+ "taskId":74708110322
50
+ }
51
+
52
+ >>> CoordinatesCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
53
+ ... ).captcha_handler(captcha_file="src/examples/088636.png")
54
+ {
55
+ "errorId":0,
56
+ "status":"ready",
57
+ "solution":{
58
+ "coordinates":[
59
+ {
60
+ "x": 358,
61
+ "y": 268
62
+ }
63
+ ],
64
+ },
65
+ "cost":0.033,
66
+ "ip":"46.53.241.91",
67
+ "createTime":1696730723,
68
+ "endTime":1696730723,
69
+ "solveCount":1,
70
+ "taskId":74708110322
71
+ }
72
+
73
+ >>> with open("src/examples/088636.png", "rb") as f:
74
+ ... file_data = f.read()
75
+ >>> CoordinatesCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
76
+ ... ).captcha_handler(captcha_base64=file_data)
77
+ {
78
+ "errorId":0,
79
+ "status":"ready",
80
+ "solution":{
81
+ "coordinates":[
82
+ {
83
+ "x": 358,
84
+ "y": 268
85
+ }
86
+ ],
87
+ },
88
+ "cost":0.033,
89
+ "ip":"46.53.241.91",
90
+ "createTime":1696730723,
91
+ "endTime":1696730723,
92
+ "solveCount":1,
93
+ "taskId":74708110322
94
+ }
95
+
96
+ >>> await CoordinatesCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
97
+ ... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
98
+ {
99
+ "errorId":0,
100
+ "status":"ready",
101
+ "solution":{
102
+ "coordinates":[
103
+ {
104
+ "x": 358,
105
+ "y": 268
106
+ }
107
+ ],
108
+ },
109
+ "cost":0.033,
110
+ "ip":"46.53.241.91",
111
+ "createTime":1696730723,
112
+ "endTime":1696730723,
113
+ "solveCount":1,
114
+ "taskId":74708110322
115
+ }
116
+
117
+ >>> await CoordinatesCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
118
+ ... ).aio_captcha_handler(captcha_file="src/examples/088636.png")
119
+ {
120
+ "errorId":0,
121
+ "status":"ready",
122
+ "solution":{
123
+ "coordinates":[
124
+ {
125
+ "x": 358,
126
+ "y": 268
127
+ }
128
+ ],
129
+ },
130
+ "cost":0.033,
131
+ "ip":"46.53.241.91",
132
+ "createTime":1696730723,
133
+ "endTime":1696730723,
134
+ "solveCount":1,
135
+ "taskId":74708110322
136
+ }
137
+
138
+ Death Captcha
139
+
140
+ >>> CoordinatesCaptcha(rucaptcha_key="some_username:some_password",
141
+ ... service_type="deathbycaptcha"
142
+ ... ).captcha_handler(captcha_file="src/examples/088636.jpg")
143
+ {
144
+ "errorId":0,
145
+ "status":"ready",
146
+ "solution":{
147
+ "coordinates":[
148
+ {
149
+ "x": 358,
150
+ "y": 268
151
+ }
152
+ ],
153
+ },
154
+ "cost":0.033,
155
+ "ip":"46.53.241.91",
156
+ "createTime":1696730723,
157
+ "endTime":1696730723,
158
+ "solveCount":1,
159
+ "taskId":74708110322
160
+ }
161
+
162
+ >>> await CoordinatesCaptcha(rucaptcha_key="some_username:some_password",
163
+ ... service_type="deathbycaptcha"
164
+ ... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
165
+ {
166
+ "errorId":0,
167
+ "status":"ready",
168
+ "solution":{
169
+ "coordinates":[
170
+ {
171
+ "x": 358,
172
+ "y": 268
173
+ }
174
+ ],
175
+ },
176
+ "cost":0.033,
177
+ "ip":"46.53.241.91",
178
+ "createTime":1696730723,
179
+ "endTime":1696730723,
180
+ "solveCount":1,
181
+ "taskId":74708110322
182
+ }
183
+
184
+ >>> with open("src/examples/088636.png", "rb") as f:
185
+ ... file_data = f.read()
186
+ >>> await CoordinatesCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
187
+ ... ).aio_captcha_handler(captcha_base64=file_data)
188
+ {
189
+ "errorId":0,
190
+ "status":"ready",
191
+ "solution":{
192
+ "coordinates":[
193
+ {
194
+ "x": 358,
195
+ "y": 268
196
+ }
197
+ ],
198
+ },
199
+ "cost":0.033,
200
+ "ip":"46.53.241.91",
201
+ "createTime":1696730723,
202
+ "endTime":1696730723,
203
+ "solveCount":1,
204
+ "taskId":74708110322
205
+ }
206
+
207
+ Returns:
208
+ Dict with full server response
209
+
210
+ Notes:
211
+ https://2captcha.com/api-docs/coordinates
212
+
213
+ https://rucaptcha.com/api-docs/coordinates
214
+ """
215
+ super().__init__(method=CoordinatesCaptchaEnm.CoordinatesTask.value, *args, **kwargs)
216
+
217
+ self.save_format = save_format
218
+ self.img_clearing = img_clearing
219
+ self.img_path = img_path
220
+
221
+ self.create_task_payload["task"].update({"comment": comment})
222
+
223
+ def captcha_handler(
224
+ self,
225
+ captcha_link: Optional[str] = None,
226
+ captcha_file: Optional[str] = None,
227
+ captcha_base64: Optional[bytes] = None,
228
+ **kwargs,
229
+ ) -> dict:
230
+ """
231
+ Sync solving method
232
+
233
+ Args:
234
+ captcha_link: Captcha image URL
235
+ captcha_file: Captcha image file path
236
+ captcha_base64: Captcha image BASE64 info
237
+ kwargs: additional params for `requests` library
238
+
239
+ Returns:
240
+ Dict with full server response
241
+
242
+ Notes:
243
+ Check class docstirng for more info
244
+ """
245
+ self._body_file_processing(
246
+ save_format=self.save_format,
247
+ file_path=self.img_path,
248
+ captcha_link=captcha_link,
249
+ captcha_file=captcha_file,
250
+ captcha_base64=captcha_base64,
251
+ **kwargs,
252
+ )
253
+ logging.warning(f"{self.result = }")
254
+ logging.warning(f"{self.create_task_payload = }")
255
+ if not self.result.errorId:
256
+ return self._processing_response(**kwargs)
257
+ return self.result.to_dict()
258
+
259
+ async def aio_captcha_handler(
260
+ self,
261
+ captcha_link: Optional[str] = None,
262
+ captcha_file: Optional[str] = None,
263
+ captcha_base64: Optional[bytes] = None,
264
+ **kwargs,
265
+ ) -> dict:
266
+ """
267
+ Async solving method
268
+
269
+ Args:
270
+ captcha_link: Captcha image URL
271
+ captcha_file: Captcha image file path
272
+ captcha_base64: Captcha image BASE64 info
273
+ kwargs: additional params for `aiohttp` library
274
+
275
+ Returns:
276
+ Dict with full server response
277
+
278
+ Notes:
279
+ Check class docstirng for more info
280
+ """
281
+ await self._aio_body_file_processing(
282
+ save_format=self.save_format,
283
+ file_path=self.img_path,
284
+ captcha_link=captcha_link,
285
+ captcha_file=captcha_file,
286
+ captcha_base64=captcha_base64,
287
+ **kwargs,
288
+ )
289
+ if not self.result.errorId:
290
+ return await self._aio_processing_response()
291
+ return self.result.to_dict()
292
+
293
+ def __del__(self):
294
+ if self.save_format == SaveFormatsEnm.CONST.value and self.img_clearing:
295
+ shutil.rmtree(self.img_path)
File without changes