-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from AndreiDrang/master
Added CyberSiARA
- Loading branch information
Showing
7 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CyberSiARA | ||
========== | ||
|
||
To import this module: | ||
|
||
.. code-block:: python | ||
from python_rucaptcha.cyber_siara_captcha import CyberSiARACaptcha | ||
.. autoclass:: python_rucaptcha.cyber_siara_captcha.CyberSiARACaptcha | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
from typing import Union | ||
|
||
from .core.base import BaseCaptcha | ||
from .core.enums import CyberSiARAEnm | ||
|
||
|
||
class CyberSiARACaptcha(BaseCaptcha): | ||
def __init__( | ||
self, | ||
websiteURL: str, | ||
SlideMasterUrlId: str, | ||
userAgent: str, | ||
method: Union[str, CyberSiARAEnm] = CyberSiARAEnm.AntiCyberSiAraTaskProxyless.value, | ||
*args, | ||
**kwargs, | ||
): | ||
""" | ||
The class is used to work with HCaptcha. | ||
Args: | ||
rucaptcha_key: User API key | ||
websiteURL: Full URL of the captcha page | ||
SlideMasterUrlId: The value of the `MasterUrlId` parameter obtained from the request to the endpoint `API/CyberSiara/GetCyberSiara`. | ||
userAgent: User-Agent of your browser will be used to load the captcha. Use only modern browser's User-Agents | ||
method: Captcha type | ||
kwargs: Not required params for task creation request | ||
Examples: | ||
>>> CyberSiARACaptcha(rucaptcha_key="aa9011f31111181111168611f1151122", | ||
... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651", | ||
... SlideMasterUrlId="https://rucaptcha.com/demo/hcaptcha", | ||
... userAgent="Mozilla/5.0 (Windows .....", | ||
... method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless, | ||
... ).captcha_handler() | ||
{ | ||
"errorId":0, | ||
"status":"ready", | ||
"solution":{ | ||
"token": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax" | ||
}, | ||
"cost":"0.00299", | ||
"ip":"1.2.3.4", | ||
"createTime":1692863536, | ||
"endTime":1692863556, | ||
"solveCount":1, | ||
"taskId": 73243152973, | ||
} | ||
>>> await CyberSiARACaptcha(rucaptcha_key="aa9011f31111181111168611f1151122", | ||
... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651", | ||
... SlideMasterUrlId="https://rucaptcha.com/demo/hcaptcha", | ||
... userAgent="Mozilla/5.0 (Windows .....", | ||
... method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless, | ||
... ).aio_captcha_handler() | ||
{ | ||
"errorId":0, | ||
"status":"ready", | ||
"solution":{ | ||
"token": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax" | ||
}, | ||
"cost":"0.00299", | ||
"ip":"1.2.3.4", | ||
"createTime":1692863536, | ||
"endTime":1692863556, | ||
"solveCount":1, | ||
"taskId": 73243152973, | ||
} | ||
Returns: | ||
Dict with full server response | ||
Notes: | ||
https://rucaptcha.com/api-docs/anti-cyber-siara#cybersiara | ||
""" | ||
super().__init__(method=method, *args, **kwargs) | ||
|
||
self.create_task_payload["task"].update( | ||
{"websiteURL": websiteURL, "SlideMasterUrlId": SlideMasterUrlId, "userAgent": userAgent} | ||
) | ||
# check user params | ||
if method not in CyberSiARAEnm.list_values(): | ||
raise ValueError(f"Invalid method parameter set, available - {CyberSiARAEnm.list_values()}") | ||
|
||
def captcha_handler(self, **kwargs) -> dict: | ||
""" | ||
Sync solving method | ||
Args: | ||
kwargs: Parameters for the `requests` library | ||
Returns: | ||
Dict with full server response | ||
Notes: | ||
Check class docstirng for more info | ||
""" | ||
|
||
return self._processing_response(**kwargs) | ||
|
||
async def aio_captcha_handler(self) -> dict: | ||
""" | ||
Async solving method | ||
Returns: | ||
Dict with full server response | ||
Notes: | ||
Check class docstirng for more info | ||
""" | ||
return await self._aio_processing_response() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import pytest | ||
|
||
from tests.conftest import BaseTest | ||
from python_rucaptcha.core.enums import CyberSiARAEnm | ||
from python_rucaptcha.cyber_siara_captcha import CyberSiARACaptcha | ||
|
||
|
||
class TestHCaptcha(BaseTest): | ||
websiteURL = "https://www.pokemoncenter.com/" | ||
SlideMasterUrlId = "OXR2LVNvCuXykkZbB8KZIfh162sNT8S2" | ||
userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" | ||
|
||
kwargs_params = { | ||
"proxyLogin": "user23", | ||
"proxyPassword": "p4$$w0rd", | ||
"proxyType": "socks5", | ||
"proxyAddress": BaseTest.proxyAddress, | ||
"proxyPort": BaseTest.proxyPort, | ||
} | ||
|
||
def test_methods_exists(self): | ||
assert "captcha_handler" in CyberSiARACaptcha.__dict__.keys() | ||
assert "aio_captcha_handler" in CyberSiARACaptcha.__dict__.keys() | ||
|
||
@pytest.mark.parametrize("method", CyberSiARAEnm.list_values()) | ||
def test_args(self, method: str): | ||
instance = CyberSiARACaptcha( | ||
rucaptcha_key=self.RUCAPTCHA_KEY, | ||
websiteURL=self.websiteURL, | ||
SlideMasterUrlId=self.SlideMasterUrlId, | ||
userAgent=self.userAgent, | ||
method=method, | ||
) | ||
assert instance.create_task_payload["clientKey"] == self.RUCAPTCHA_KEY | ||
assert instance.create_task_payload["task"]["type"] == method | ||
assert instance.create_task_payload["task"]["websiteURL"] == self.websiteURL | ||
assert instance.create_task_payload["task"]["SlideMasterUrlId"] == self.SlideMasterUrlId | ||
assert instance.create_task_payload["task"]["userAgent"] == self.userAgent | ||
|
||
def test_kwargs(self): | ||
instance = CyberSiARACaptcha( | ||
rucaptcha_key=self.RUCAPTCHA_KEY, | ||
websiteURL=self.websiteURL, | ||
SlideMasterUrlId=self.SlideMasterUrlId, | ||
userAgent=self.userAgent, | ||
method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless, | ||
**self.kwargs_params, | ||
) | ||
assert set(self.kwargs_params.keys()).issubset(set(instance.create_task_payload["task"].keys())) | ||
assert set(self.kwargs_params.values()).issubset(set(instance.create_task_payload["task"].values())) | ||
|
||
""" | ||
Fail tests | ||
""" | ||
|
||
def test_no_websiteURL(self): | ||
with pytest.raises(TypeError): | ||
CyberSiARACaptcha( | ||
rucaptcha_key=self.RUCAPTCHA_KEY, | ||
SlideMasterUrlId=self.SlideMasterUrlId, | ||
userAgent=self.userAgent, | ||
method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless, | ||
) | ||
|
||
def test_no_SlideMasterUrlId(self): | ||
with pytest.raises(TypeError): | ||
CyberSiARACaptcha( | ||
rucaptcha_key=self.RUCAPTCHA_KEY, | ||
websiteURL=self.websiteURL, | ||
userAgent=self.userAgent, | ||
method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless, | ||
) | ||
|
||
def test_no_userAgent(self): | ||
with pytest.raises(TypeError): | ||
CyberSiARACaptcha( | ||
rucaptcha_key=self.RUCAPTCHA_KEY, | ||
websiteURL=self.websiteURL, | ||
SlideMasterUrlId=self.SlideMasterUrlId, | ||
method=CyberSiARAEnm.AntiCyberSiAraTaskProxyless, | ||
) | ||
|
||
def test_wrong_method(self): | ||
with pytest.raises(ValueError): | ||
CyberSiARACaptcha( | ||
rucaptcha_key=self.RUCAPTCHA_KEY, | ||
websiteURL=self.websiteURL, | ||
SlideMasterUrlId=self.SlideMasterUrlId, | ||
userAgent=self.userAgent, | ||
method=self.get_random_string(length=5), | ||
) |