Skip to content

Commit

Permalink
Merge pull request #196 from AndreiDrang/master
Browse files Browse the repository at this point in the history
Added CyberSiARA
  • Loading branch information
AndreiDrang authored Dec 10, 2023
2 parents f4bf7a5 + 832c61b commit a9eb8fa
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
lemin_captcha,
rotate_captcha,
datadome_captcha,
cyber_siara_captcha,
)
from python_rucaptcha.__version__ import __version__

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Check our other projects here - `RedPandaDev group <https://red-panda-dev.xyz/bl
modules/audio/example.rst
modules/cut-captcha/example.rst
modules/datadome-captcha/example.rst
modules/cyber-siara-captcha/example.rst
modules/control/example.rst

.. toctree::
Expand Down
12 changes: 12 additions & 0 deletions docs/modules/cyber-siara-captcha/example.rst
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:
4 changes: 4 additions & 0 deletions docs/modules/enum/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
5 changes: 5 additions & 0 deletions src/python_rucaptcha/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,8 @@ class CutCaptchaEnm(str, MyEnum):

class DataDomeSliderEnm(str, MyEnum):
DataDomeSliderTask = "DataDomeSliderTask"


class CyberSiARAEnm(str, MyEnum):
AntiCyberSiAraTask = "AntiCyberSiAraTask"
AntiCyberSiAraTaskProxyless = "AntiCyberSiAraTaskProxyless"
110 changes: 110 additions & 0 deletions src/python_rucaptcha/cyber_siara_captcha.py
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()
91 changes: 91 additions & 0 deletions tests/test_cybersiara.py
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),
)

0 comments on commit a9eb8fa

Please sign in to comment.