-
Notifications
You must be signed in to change notification settings - Fork 14
Binance, imperva, docs #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
capmonstercloud_client/requests/BinanceTaskProxylessRequest.py
This file contains hidden or 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,17 @@ | ||
| from typing import Dict, Union | ||
|
|
||
| from .BinanceTaskRequestBase import BinanceTaskRequestBase | ||
|
|
||
|
|
||
| class BinanceTaskProxylessRequest(BinanceTaskRequestBase): | ||
| type: str = 'BinanceTaskProxyless' | ||
|
|
||
| def getTaskDict(self) -> Dict[str, Union[str, int, bool]]: | ||
| task = {} | ||
| task['type'] = self.type | ||
| task['validateId'] = self.validateId | ||
| task['websiteURL'] = self.websiteUrl | ||
| task['websiteKey'] = self.websiteKey | ||
| if self.userAgent is not None: | ||
| task['userAgent'] = self.userAgent | ||
| return task |
This file contains hidden or 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,22 @@ | ||
| from typing import Dict, Union | ||
| from pydantic import Field, validator | ||
|
|
||
| from .proxy_info import ProxyInfo | ||
| from .BinanceTaskRequestBase import BinanceTaskRequestBase | ||
|
|
||
| class BinanceTaskRequest(BinanceTaskRequestBase, ProxyInfo): | ||
|
|
||
| def getTaskDict(self) -> Dict[str, Union[str, int, bool]]: | ||
| task = {} | ||
| task['type'] = self.type | ||
| task['validateId'] = self.validateId | ||
| task['websiteURL'] = self.websiteUrl | ||
| task['websiteKey'] = self.websiteKey | ||
| task['proxyType'] = self.proxyType | ||
| task['proxyAddress'] = self.proxyAddress | ||
| task['proxyPort'] = self.proxyPort | ||
| task['proxyLogin'] = self.proxyLogin | ||
| task['proxyPassword'] = self.proxyPassword | ||
| if self.userAgent is not None: | ||
| task['userAgent'] = self.userAgent | ||
| return task |
This file contains hidden or 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,11 @@ | ||
| from .baseRequest import BaseRequest, Field | ||
| from typing import Optional | ||
|
|
||
|
|
||
| class BinanceTaskRequestBase(BaseRequest): | ||
|
|
||
| type: str = Field(default='BinanceTask') | ||
| websiteKey: str = Field() | ||
| websiteUrl: str = Field() | ||
| validateId: str = Field() | ||
| userAgent: Optional[str] = None |
33 changes: 33 additions & 0 deletions
33
capmonstercloud_client/requests/ImpervaCustomTaskProxylessRequest.py
This file contains hidden or 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,33 @@ | ||
| from typing import Dict, Union | ||
| from pydantic import Field, validator | ||
|
|
||
| from .ImpervaCustomTaskRequestBase import ImpervaCustomTaskRequestBase | ||
|
|
||
| class ImpervaCustomTaskProxylessRequest(ImpervaCustomTaskRequestBase): | ||
| metadata : Dict[str, str] | ||
|
|
||
| @validator('metadata') | ||
| def validate_metadata(cls, value): | ||
| if value.get('incapsulaScriptBase64') is None: | ||
| raise TypeError(f'Expect that incapsulaScriptBase64 will be defined.') | ||
| else: | ||
| if not isinstance(value.get('incapsulaScriptBase64'), str): | ||
| raise TypeError(f'Expect that incapsulaScriptBase64 will be str.') | ||
| if value.get('incapsulaSessionCookie') is None: | ||
| raise TypeError(f'Expect that incapsulaSessionCookie will be defined.') | ||
| else: | ||
| if not isinstance(value.get('incapsulaSessionCookie'), str): | ||
| raise TypeError(f'Expect that incapsulaSessionCookie will be str.') | ||
| if value.get('reese84UrlEndpoint') is not None and not isinstance(value.get('incapsulaSessionCookie'), str): | ||
| raise TypeError(f'Expect that reese84UrlEndpoint will be str.') | ||
| return value | ||
|
|
||
| def getTaskDict(self) -> Dict[str, Union[str, int, bool]]: | ||
| task = {} | ||
| task['type'] = self.type | ||
| task['class'] = self.captchaClass | ||
| task['websiteURL'] = self.websiteUrl | ||
| task['metadata'] = self.metadata | ||
| if self.userAgent is not None: | ||
| task['userAgent'] = self.userAgent | ||
| return task |
39 changes: 39 additions & 0 deletions
39
capmonstercloud_client/requests/ImpervaCustomTaskRequest.py
This file contains hidden or 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,39 @@ | ||
| from typing import Dict, Union | ||
| from pydantic import Field, validator | ||
|
|
||
| from .proxy_info import ProxyInfo | ||
| from .ImpervaCustomTaskRequestBase import ImpervaCustomTaskRequestBase | ||
|
|
||
| class ImpervaCustomTaskRequest(ImpervaCustomTaskRequestBase, ProxyInfo): | ||
| metadata : Dict[str, str] | ||
|
|
||
| @validator('metadata') | ||
| def validate_metadata(cls, value): | ||
| if value.get('incapsulaScriptBase64') is None: | ||
| raise TypeError(f'Expect that incapsulaScriptBase64 will be defined.') | ||
| else: | ||
| if not isinstance(value.get('incapsulaScriptBase64'), str): | ||
| raise TypeError(f'Expect that incapsulaScriptBase64 will be str.') | ||
| if value.get('incapsulaSessionCookie') is None: | ||
| raise TypeError(f'Expect that incapsulaSessionCookie will be defined.') | ||
| else: | ||
| if not isinstance(value.get('incapsulaSessionCookie'), str): | ||
| raise TypeError(f'Expect that incapsulaSessionCookie will be str.') | ||
| if value.get('reese84UrlEndpoint') is not None and not isinstance(value.get('incapsulaSessionCookie'), str): | ||
| raise TypeError(f'Expect that reese84UrlEndpoint will be str.') | ||
| return value | ||
|
|
||
| def getTaskDict(self) -> Dict[str, Union[str, int, bool]]: | ||
| task = {} | ||
| task['type'] = self.type | ||
| task['class'] = self.captchaClass | ||
| task['websiteURL'] = self.websiteUrl | ||
| task['metadata'] = self.metadata | ||
| task['proxyType'] = self.proxyType | ||
| task['proxyAddress'] = self.proxyAddress | ||
| task['proxyPort'] = self.proxyPort | ||
| task['proxyLogin'] = self.proxyLogin | ||
| task['proxyPassword'] = self.proxyPassword | ||
| if self.userAgent is not None: | ||
| task['userAgent'] = self.userAgent | ||
| return task |
8 changes: 8 additions & 0 deletions
8
capmonstercloud_client/requests/ImpervaCustomTaskRequestBase.py
This file contains hidden or 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,8 @@ | ||
| from typing import Dict, Union | ||
| from pydantic import Field | ||
|
|
||
| from .CustomTaskRequestBase import CustomTaskRequestBase | ||
|
|
||
| class ImpervaCustomTaskRequestBase(CustomTaskRequestBase): | ||
| type: str = Field(default='CustomTask') | ||
| captchaClass: str = Field(default='Imperva') |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.5.2 | ||
azeriker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 1.6.0 | ||
This file contains hidden or 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,37 @@ | ||
| import os | ||
| import time | ||
| import asyncio | ||
|
|
||
| from capmonstercloudclient.requests import BinanceTaskProxylessRequest | ||
| from capmonstercloudclient import ClientOptions, CapMonsterClient | ||
|
|
||
| async def solve_captcha_sync(num_requests): | ||
| return [await cap_monster_client.solve_captcha(datadome_request) for _ in range(num_requests)] | ||
|
|
||
| async def solve_captcha_async(num_requests): | ||
| tasks = [asyncio.create_task(cap_monster_client.solve_captcha(datadome_request)) | ||
| for _ in range(num_requests)] | ||
| return await asyncio.gather(*tasks, return_exceptions=True) | ||
|
|
||
| if __name__ == '__main__': | ||
| key = os.getenv('API_KEY') | ||
| client_options = ClientOptions(api_key=key) | ||
| cap_monster_client = CapMonsterClient(options=client_options) | ||
| datadome_request = BinanceTaskProxylessRequest( | ||
| websiteUrl='https://accounts.binance.com/ru/login?loginChannel=&return_to=', | ||
| websiteKey='login', | ||
| validateId="2b8137c0b9b44189800368819354e114" | ||
| ) | ||
| nums = 3 | ||
|
|
||
| # Sync test | ||
| sync_start = time.time() | ||
| sync_responses = asyncio.run(solve_captcha_sync(nums)) | ||
| print(f'average execution time sync {1/((time.time()-sync_start)/nums):0.2f} ' \ | ||
| f'resp/sec\nsolution: {sync_responses[0]}') | ||
|
|
||
| # Async test | ||
| async_start = time.time() | ||
| async_responses = asyncio.run(solve_captcha_async(nums)) | ||
| print(f'average execution time async {1/((time.time()-async_start)/nums):0.2f} ' \ | ||
| f'resp/sec\nsolution: {async_responses[0]}') |
This file contains hidden or 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,40 @@ | ||
| import os | ||
| import time | ||
| import asyncio | ||
|
|
||
| from capmonstercloudclient.requests import ImpervaCustomTaskProxylessRequest | ||
| from capmonstercloudclient import ClientOptions, CapMonsterClient | ||
| import json | ||
|
|
||
| async def solve_captcha_sync(num_requests): | ||
| return [await cap_monster_client.solve_captcha(datadome_request) for _ in range(num_requests)] | ||
|
|
||
| async def solve_captcha_async(num_requests): | ||
| tasks = [asyncio.create_task(cap_monster_client.solve_captcha(datadome_request)) | ||
| for _ in range(num_requests)] | ||
| return await asyncio.gather(*tasks, return_exceptions=True) | ||
|
|
||
| if __name__ == '__main__': | ||
| key = os.getenv('API_KEY') | ||
| client_options = ClientOptions(api_key=key) | ||
| cap_monster_client = CapMonsterClient(options=client_options) | ||
| metadata = {"incapsulaScriptBase64": "", | ||
| "incapsulaSessionCookie": "SAyLRzdYgUntD6v0r7nFBmxTYGcAAAAArkznhRMmVs/cBynTg3r6YA==", | ||
| "reese84UrlEndpoint": "Alarums-Exeunter-Hath-Brese-Banq-Wheth-frangerd-"} | ||
| datadome_request = ImpervaCustomTaskProxylessRequest( | ||
| websiteUrl='https://example.com/login', | ||
| metadata=metadata | ||
| ) | ||
| nums = 3 | ||
|
|
||
| # Sync test | ||
| sync_start = time.time() | ||
| sync_responses = asyncio.run(solve_captcha_sync(nums)) | ||
| print(f'average execution time sync {1/((time.time()-sync_start)/nums):0.2f} ' \ | ||
| f'resp/sec\nsolution: {sync_responses[0]}') | ||
|
|
||
| # Async test | ||
| async_start = time.time() | ||
| async_responses = asyncio.run(solve_captcha_async(nums)) | ||
| print(f'average execution time async {1/((time.time()-async_start)/nums):0.2f} ' \ | ||
| f'resp/sec\nsolution: {async_responses[0]}') |
This file contains hidden or 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,45 @@ | ||
| import unittest | ||
| from copy import deepcopy | ||
|
|
||
| from pydantic import ValidationError | ||
| from capmonstercloudclient.requests import BinanceTaskProxylessRequest | ||
|
|
||
|
|
||
| class BinanceRequestTest(unittest.TestCase): | ||
|
|
||
| websiteUrlExample = 'https://binance.com/login' | ||
| websiteKeyExample = 'login' | ||
| userAgentExample = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' | ||
|
|
||
| def test_binance(self, | ||
| ): | ||
| required_fields = ['type', | ||
| 'websiteURL', | ||
| 'websiteKey', | ||
| 'validateId'] | ||
| request = BinanceTaskProxylessRequest(websiteKey=self.websiteKeyExample, | ||
| websiteUrl=self.websiteUrlExample, | ||
| validateId='asdgf') | ||
| task_dictionary = request.getTaskDict() | ||
| for f in required_fields: | ||
| self.assertTrue(f in list(task_dictionary.keys()), | ||
| msg=f'Required captcha input key "{f}" does not include to request.') | ||
|
|
||
| def test_binance_missing(self,): | ||
| required_fields = ['type', | ||
| 'websiteURL', | ||
| 'websiteKey', | ||
| 'validateId'] | ||
| base_kwargs = {} | ||
| self.assertRaises(ValidationError, BinanceTaskProxylessRequest, **base_kwargs) | ||
| base_kwargs.update({'websiteUrl': self.websiteUrlExample}) | ||
| self.assertRaises(ValidationError, BinanceTaskProxylessRequest, **base_kwargs) | ||
| base_kwargs.update({'websiteKey': self.websiteKeyExample}) | ||
| self.assertRaises(ValidationError, BinanceTaskProxylessRequest, **base_kwargs) | ||
| base_kwargs.update({'validateId': 'asdgf'}) | ||
| BinanceTaskProxylessRequest(**base_kwargs) | ||
| base_kwargs.update({'userAgent': self.userAgentExample}) | ||
| BinanceTaskProxylessRequest(**base_kwargs) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.