From ecbec80863109ffa727f860945c3dff6bbbeb4ec Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:47:58 +0300 Subject: [PATCH 1/7] Update conf.py --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 6f7b0779..cb60cca5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,6 +19,7 @@ lemin_captcha, rotate_captcha, datadome_captcha, + cyber_siara_captcha, ) from python_rucaptcha.__version__ import __version__ From bf7d23e3ea2d1383d7183d61968f1f2db7e0766e Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:48:02 +0300 Subject: [PATCH 2/7] Create test_cybersiara.py --- tests/test_cybersiara.py | 91 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/test_cybersiara.py diff --git a/tests/test_cybersiara.py b/tests/test_cybersiara.py new file mode 100644 index 00000000..3e591242 --- /dev/null +++ b/tests/test_cybersiara.py @@ -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), + ) From a39d2a66ceb10874dad26ff3b2691c6ffab71d9a Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:48:07 +0300 Subject: [PATCH 3/7] Create cyber_siara_captcha.py --- src/python_rucaptcha/cyber_siara_captcha.py | 110 ++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/python_rucaptcha/cyber_siara_captcha.py diff --git a/src/python_rucaptcha/cyber_siara_captcha.py b/src/python_rucaptcha/cyber_siara_captcha.py new file mode 100644 index 00000000..13c9189d --- /dev/null +++ b/src/python_rucaptcha/cyber_siara_captcha.py @@ -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() From 66cd7b93cd9381bd8611acd9c9d50fe88d996555 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:48:10 +0300 Subject: [PATCH 4/7] Update enums.py --- src/python_rucaptcha/core/enums.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/python_rucaptcha/core/enums.py b/src/python_rucaptcha/core/enums.py index d45ce1cc..f46ba606 100644 --- a/src/python_rucaptcha/core/enums.py +++ b/src/python_rucaptcha/core/enums.py @@ -118,3 +118,8 @@ class CutCaptchaEnm(str, MyEnum): class DataDomeSliderEnm(str, MyEnum): DataDomeSliderTask = "DataDomeSliderTask" + + +class CyberSiARAEnm(str, MyEnum): + AntiCyberSiAraTask = "AntiCyberSiAraTask" + AntiCyberSiAraTaskProxyless = "AntiCyberSiAraTaskProxyless" From 77e1ccbfae79ea94964378c49a04c992459f78ea Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:48:13 +0300 Subject: [PATCH 5/7] Update info.rst --- docs/modules/enum/info.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/modules/enum/info.rst b/docs/modules/enum/info.rst index ef7914a4..903a0ae3 100644 --- a/docs/modules/enum/info.rst +++ b/docs/modules/enum/info.rst @@ -75,3 +75,7 @@ To import this module: .. autoclass:: python_rucaptcha.core.enums.DataDomeSliderEnm :members: :undoc-members: + +.. autoclass:: python_rucaptcha.core.enums.CyberSiARAEnm + :members: + :undoc-members: From 632a70139004a8c1152184b7fb9ac7cc3394373e Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:48:15 +0300 Subject: [PATCH 6/7] Create example.rst --- docs/modules/cyber-siara-captcha/example.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 docs/modules/cyber-siara-captcha/example.rst diff --git a/docs/modules/cyber-siara-captcha/example.rst b/docs/modules/cyber-siara-captcha/example.rst new file mode 100644 index 00000000..f92a85c1 --- /dev/null +++ b/docs/modules/cyber-siara-captcha/example.rst @@ -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: \ No newline at end of file From 832c61b6b0e08250d80363c799679cbdb8cd2982 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Dec 2023 23:48:20 +0300 Subject: [PATCH 7/7] Update index.rst --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index fbebfb8b..e767ca33 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -42,6 +42,7 @@ Check our other projects here - `RedPandaDev group