|
1 | 1 | import aiohttp |
2 | 2 | import requests |
3 | 3 |
|
4 | | -from python3_anticaptcha import ( |
5 | | - get_balance_url, |
6 | | - get_app_stats_url, |
7 | | - get_queue_status_url, |
8 | | - incorrect_recaptcha_url, |
9 | | - incorrect_imagecaptcha_url, |
10 | | -) |
| 4 | +# Адрес для получения баланса |
| 5 | +get_balance_url = "https://api.anti-captcha.com/getBalance" |
| 6 | +# Адрес для отправки жалобы на неверное решение капчи-изображения |
| 7 | +incorrect_imagecaptcha_url = "https://api.anti-captcha.com/reportIncorrectImageCaptcha" |
| 8 | +# Адрес для отправки жалобы на неверное решение ReCaptcha |
| 9 | +incorrect_recaptcha_url = "https://api.anti-captcha.com/reportIncorrectRecaptcha" |
| 10 | +# Адрес для получения информации о очереди |
| 11 | +get_queue_status_url = "https://api.anti-captcha.com/getQueueStats" |
| 12 | +# С помощью этого метода можно получить статистику трат за последние 24 часа. |
| 13 | +get_spend_stats_url = "https://api.anti-captcha.com/getSpendingStats" |
| 14 | +# Адрес для получения информации о приложении |
| 15 | +get_app_stats_url = "https://api.anti-captcha.com/getAppStats" |
| 16 | +# С помощью этого метода можно получить статистику трат за последние 24 часа. |
| 17 | +send_funds_url = "https://api.anti-captcha.com/sendFunds" |
11 | 18 |
|
12 | 19 | # available app stats mods |
13 | 20 | mods = ("errors", "views", "downloads", "users", "money") |
14 | 21 | # available complaint captcha types |
15 | 22 | complaint_types = ("image", "recaptcha") |
16 | 23 | # availalbe queue ID's |
17 | | -queue_ids = (1, 2, 5, 6, 7, 10) |
| 24 | +queue_ids = (1, 2, 5, 6, 7, 10, 11, 12, 13, 18, 19, 20) |
| 25 | + |
| 26 | +queues_names = ( |
| 27 | + "English ImageToText", |
| 28 | + "Russian ImageToText", |
| 29 | + "Recaptcha Proxy-on", |
| 30 | + "Recaptcha Proxyless", |
| 31 | + "FunCaptcha", |
| 32 | + "Funcaptcha Proxyless", |
| 33 | + "Square Net Task", |
| 34 | + "GeeTest Proxy-on", |
| 35 | + "GeeTest Proxyless", |
| 36 | +) |
18 | 37 |
|
19 | 38 |
|
20 | 39 | class AntiCaptchaControl: |
@@ -44,6 +63,56 @@ def get_balance(self) -> dict: |
44 | 63 |
|
45 | 64 | return answer.json() |
46 | 65 |
|
| 66 | + def send_funds( |
| 67 | + self, accountLogin: str = None, accountEmail: str = None, amount: float = None |
| 68 | + ) -> dict: |
| 69 | + """ |
| 70 | + Отправить средства другому пользователю |
| 71 | + В вашем аккаунте должна быть включена опция отправки средств через API. |
| 72 | + Включается через службу поддержки, нужно указать причину зачем вам это требуется. |
| 73 | +
|
| 74 | + :param accountLogin: Логин целевого аккаунта |
| 75 | + :param accountEmail: Адрес почты целевого аккаунта |
| 76 | + :param amount: Сумма |
| 77 | + """ |
| 78 | + payload = { |
| 79 | + "clientKey": self.ANTICAPTCHA_KEY, |
| 80 | + "accountLogin": accountLogin, |
| 81 | + "accountEmail": accountEmail, |
| 82 | + "amount": amount, |
| 83 | + } |
| 84 | + # get response |
| 85 | + answer = requests.post(send_funds_url, json=payload, verify=False) |
| 86 | + return answer.json() |
| 87 | + |
| 88 | + def get_spend_stats( |
| 89 | + self, date: int = None, queue: str = None, softId: int = None, ip: str = None |
| 90 | + ) -> dict: |
| 91 | + f""" |
| 92 | + С помощью этого метода можно получить статистику трат за последние 24 часа. |
| 93 | + :param date: Unix timestamp начала периода 24-х часового отчета |
| 94 | + :param queue: Имя очереди, может быть найдено в статистике Антикапчи. |
| 95 | + Если не указано, то возвращается суммированная статистика по всем очередям. |
| 96 | + :param softId: ID приложения из Developers Center |
| 97 | + :param ip: IP с которого шли запросы к API |
| 98 | + :return: Возвращает словарь с данными трат |
| 99 | + """ |
| 100 | + if queue and queue not in queues_names: |
| 101 | + raise ValueError( |
| 102 | + f"\nWrong `queue` parameter. Valid params: {queues_names}." |
| 103 | + f"\n\tYour param - `{queue}`" |
| 104 | + ) |
| 105 | + payload = { |
| 106 | + "clientKey": self.ANTICAPTCHA_KEY, |
| 107 | + "date": date, |
| 108 | + "queue": queue, |
| 109 | + "softId": softId, |
| 110 | + "ip": ip, |
| 111 | + } |
| 112 | + # get response |
| 113 | + answer = requests.post(get_spend_stats_url, json=payload, verify=False) |
| 114 | + return answer.json() |
| 115 | + |
47 | 116 | def get_app_stats(self, softId: int, mode: str = "errors") -> dict: |
48 | 117 | """ |
49 | 118 | Получение статистики приложения |
@@ -98,6 +167,12 @@ def get_queue_status(queue_id: int) -> dict: |
98 | 167 | 6 - Recaptcha Proxyless |
99 | 168 | 7 - Funcaptcha |
100 | 169 | 10 - Funcaptcha Proxyless |
| 170 | + 11 - Square Net Task |
| 171 | + 12 - GeeTest Proxy-On |
| 172 | + 13 - GeeTest Proxyless |
| 173 | + 18 - Recaptcha V3 s0.3 |
| 174 | + 19 - Recaptcha V3 s0.7 |
| 175 | + 20 - Recaptcha V3 s0.9 |
101 | 176 |
|
102 | 177 | Пример выдачи ответа: |
103 | 178 | { |
@@ -148,7 +223,68 @@ async def get_balance(self) -> dict: |
148 | 223 | async with session.post( |
149 | 224 | get_balance_url, json={"clientKey": self.ANTICAPTCHA_KEY} |
150 | 225 | ) as resp: |
151 | | - return await resp.json() |
| 226 | + if await resp.text(): |
| 227 | + return await resp.json() |
| 228 | + else: |
| 229 | + return {"errorId": 1} |
| 230 | + |
| 231 | + async def send_funds( |
| 232 | + self, accountLogin: str = None, accountEmail: str = None, amount: float = None |
| 233 | + ) -> dict: |
| 234 | + """ |
| 235 | + Отправить средства другому пользователю |
| 236 | + В вашем аккаунте должна быть включена опция отправки средств через API. |
| 237 | + Включается через службу поддержки, нужно указать причину зачем вам это требуется. |
| 238 | +
|
| 239 | + :param accountLogin: Логин целевого аккаунта |
| 240 | + :param accountEmail: Адрес почты целевого аккаунта |
| 241 | + :param amount: Сумма |
| 242 | + """ |
| 243 | + payload = { |
| 244 | + "clientKey": self.ANTICAPTCHA_KEY, |
| 245 | + "accountLogin": accountLogin, |
| 246 | + "accountEmail": accountEmail, |
| 247 | + "amount": amount, |
| 248 | + } |
| 249 | + # get response |
| 250 | + async with aiohttp.ClientSession() as session: |
| 251 | + async with session.post(send_funds_url, json=payload) as resp: |
| 252 | + if await resp.text(): |
| 253 | + return await resp.json() |
| 254 | + else: |
| 255 | + return {"errorId": 1} |
| 256 | + |
| 257 | + async def get_spend_stats( |
| 258 | + self, date: int = None, queue: str = None, softId: int = None, ip: str = None |
| 259 | + ) -> dict: |
| 260 | + f""" |
| 261 | + С помощью этого метода можно получить статистику трат за последние 24 часа. |
| 262 | + :param date: Unix timestamp начала периода 24-х часового отчета |
| 263 | + :param queue: Имя очереди, может быть найдено в статистике Антикапчи. |
| 264 | + Если не указано, то возвращается суммированная статистика по всем очередям. |
| 265 | + :param softId: ID приложения из Developers Center |
| 266 | + :param ip: IP с которого шли запросы к API |
| 267 | + :return: Возвращает словарь с данными трат |
| 268 | + """ |
| 269 | + if queue and queue not in queues_names: |
| 270 | + raise ValueError( |
| 271 | + f"\nWrong `queue` parameter. Valid params: {queues_names}." |
| 272 | + f"\n\tYour param - `{queue}`" |
| 273 | + ) |
| 274 | + payload = { |
| 275 | + "clientKey": self.ANTICAPTCHA_KEY, |
| 276 | + "date": date, |
| 277 | + "queue": queue, |
| 278 | + "softId": softId, |
| 279 | + "ip": ip, |
| 280 | + } |
| 281 | + # get response |
| 282 | + async with aiohttp.ClientSession() as session: |
| 283 | + async with session.post(get_spend_stats_url, json=payload) as resp: |
| 284 | + if await resp.text(): |
| 285 | + return await resp.json() |
| 286 | + else: |
| 287 | + return {"errorId": 1} |
152 | 288 |
|
153 | 289 | async def get_app_stats(self, softId: int, mode: str = "errors") -> dict: |
154 | 290 | """ |
@@ -185,12 +321,18 @@ async def complaint_on_result(self, reported_id: int, captcha_type: str = "image |
185 | 321 | if captcha_type == "image": |
186 | 322 | async with aiohttp.ClientSession() as session: |
187 | 323 | async with session.post(incorrect_imagecaptcha_url, json=payload) as resp: |
188 | | - return await resp.json() |
| 324 | + if await resp.text(): |
| 325 | + return await resp.json() |
| 326 | + else: |
| 327 | + return {"errorId": 1} |
189 | 328 | # complaint on re-captcha |
190 | 329 | elif captcha_type == "recaptcha": |
191 | 330 | async with aiohttp.ClientSession() as session: |
192 | 331 | async with session.post(incorrect_recaptcha_url, json=payload) as resp: |
193 | | - return await resp.json() |
| 332 | + if await resp.text(): |
| 333 | + return await resp.json() |
| 334 | + else: |
| 335 | + return {"errorId": 1} |
194 | 336 |
|
195 | 337 | @staticmethod |
196 | 338 | async def get_queue_status(queue_id: int) -> dict: |
@@ -228,4 +370,7 @@ async def get_queue_status(queue_id: int) -> dict: |
228 | 370 |
|
229 | 371 | async with aiohttp.ClientSession() as session: |
230 | 372 | async with session.post(get_queue_status_url, json=payload) as resp: |
231 | | - return await resp.json() |
| 373 | + if await resp.text(): |
| 374 | + return await resp.json() |
| 375 | + else: |
| 376 | + return {"errorId": 1} |
0 commit comments