|
| 1 | +from typing import Union |
| 2 | + |
| 3 | +from .core.base import BaseCaptcha |
| 4 | +from .core.enums import ProsopoEnm |
| 5 | + |
| 6 | + |
| 7 | +class Prosopo(BaseCaptcha): |
| 8 | + def __init__( |
| 9 | + self, |
| 10 | + websiteURL: str, |
| 11 | + websiteKey: str, |
| 12 | + method: Union[str, ProsopoEnm] = ProsopoEnm.ProsopoTaskProxyless, |
| 13 | + *args, |
| 14 | + **kwargs, |
| 15 | + ): |
| 16 | + """ |
| 17 | + The class is used to work with Prosopo. |
| 18 | +
|
| 19 | + Args: |
| 20 | + rucaptcha_key: User API key |
| 21 | + websiteURL: The full URL of target web page where the captcha is loaded. |
| 22 | + We do not open the page, not a problem if it is available |
| 23 | + only for authenticated users |
| 24 | + websiteKey: The value of `siteKey` parameter found on the page. |
| 25 | + method: Captcha type |
| 26 | +
|
| 27 | + Examples: |
| 28 | + >>> Prosopo(rucaptcha_key="aa9011f31111181111168611f1151122", |
| 29 | + ... websiteURL="https://www.example.com/", |
| 30 | + ... websiteKey="5EPQoMZEDc5LpN7gtxMMzYPTzA6UeWqL2stk1rso9gy4Ahqt", |
| 31 | + ... method=ProsopoEnm.ProsopoTaskProxyless.value, |
| 32 | + ... ).captcha_handler() |
| 33 | + { |
| 34 | + "errorId":0, |
| 35 | + "status":"ready", |
| 36 | + "solution":{ |
| 37 | + "token": "0x00016c68747470733950547a4136", |
| 38 | + }, |
| 39 | + "cost":"0.00299", |
| 40 | + "ip":"1.2.3.4", |
| 41 | + "createTime":1692863536, |
| 42 | + "endTime":1692863556, |
| 43 | + "solveCount":1, |
| 44 | + "taskId":75190409731 |
| 45 | + } |
| 46 | +
|
| 47 | + >>> await Prosopo(rucaptcha_key="aa9011f31111181111168611f1151122", |
| 48 | + ... websiteURL="https://www.example.com/", |
| 49 | + ... websiteKey="5EPQoMZEDc5LpN7gtxMMzYPTzA6UeWqL2stk1rso9gy4Ahqt", |
| 50 | + ... method=ProsopoEnm.ProsopoTaskProxyless.value, |
| 51 | + ... ).aio_captcha_handler() |
| 52 | + { |
| 53 | + "errorId":0, |
| 54 | + "status":"ready", |
| 55 | + "solution":{ |
| 56 | + "token": "0x00016c68747470733950547a4136", |
| 57 | + }, |
| 58 | + "cost":"0.00299", |
| 59 | + "ip":"1.2.3.4", |
| 60 | + "createTime":1692863536, |
| 61 | + "endTime":1692863556, |
| 62 | + "solveCount":1, |
| 63 | + "taskId":75190409731 |
| 64 | + } |
| 65 | +
|
| 66 | + Returns: |
| 67 | + Dict with full server response |
| 68 | +
|
| 69 | + Notes: |
| 70 | + https://rucaptcha.com/api-docs/prosopo-procaptcha |
| 71 | +
|
| 72 | + https://rucaptcha.com/api-docs/prosopo-procaptcha |
| 73 | + """ |
| 74 | + super().__init__(method=method, *args, **kwargs) |
| 75 | + |
| 76 | + self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey}) |
| 77 | + |
| 78 | + # check user params |
| 79 | + if method not in ProsopoEnm.list_values(): |
| 80 | + raise ValueError(f"Invalid method parameter set, available - {ProsopoEnm.list_values()}") |
| 81 | + |
| 82 | + def captcha_handler(self, **kwargs) -> dict: |
| 83 | + """ |
| 84 | + Sync solving method |
| 85 | +
|
| 86 | + Args: |
| 87 | + kwargs: additional params for `requests` library |
| 88 | +
|
| 89 | + Returns: |
| 90 | + Dict with full server response |
| 91 | +
|
| 92 | + Notes: |
| 93 | + Check class docstirng for more info |
| 94 | + """ |
| 95 | + |
| 96 | + return self._processing_response(**kwargs) |
| 97 | + |
| 98 | + async def aio_captcha_handler(self) -> dict: |
| 99 | + """ |
| 100 | + Async solving method |
| 101 | +
|
| 102 | + Returns: |
| 103 | + Dict with full server response |
| 104 | +
|
| 105 | + Notes: |
| 106 | + Check class docstirng for more info |
| 107 | + """ |
| 108 | + return await self._aio_processing_response() |
0 commit comments