2023-05-24 17:41:33 +04:00
|
|
|
"""Stores API session and sends requests"""
|
2022-07-01 14:28:39 +04:00
|
|
|
|
2023-05-24 17:12:34 +04:00
|
|
|
import string
|
2022-10-05 19:24:00 +04:00
|
|
|
import secrets
|
2023-05-24 17:12:34 +04:00
|
|
|
|
2022-10-05 19:24:00 +04:00
|
|
|
from typing import Optional
|
2023-08-08 10:57:41 +04:00
|
|
|
from typing import Dict, Any
|
2021-10-27 19:42:41 +03:00
|
|
|
|
2023-05-24 17:41:33 +04:00
|
|
|
|
|
|
|
BASE_URL = 'https://aternos.org'
|
|
|
|
AJAX_URL = f'{BASE_URL}/ajax'
|
|
|
|
|
2023-05-24 17:12:34 +04:00
|
|
|
SEC_ALPHABET = string.ascii_lowercase + string.digits
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
|
2021-10-14 17:56:01 +04:00
|
|
|
class AternosConnect:
|
2022-09-29 18:18:15 +04:00
|
|
|
"""Class for sending API requests,
|
|
|
|
bypassing Cloudflare and parsing responses"""
|
2022-06-17 12:30:58 +04:00
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
def __init__(self) -> None:
|
2021-11-01 18:04:19 +04:00
|
|
|
|
2022-07-01 14:28:39 +04:00
|
|
|
self.sec = ''
|
|
|
|
self.token = ''
|
2022-11-03 18:01:53 +04:00
|
|
|
self.atcookie = ''
|
2021-11-01 18:04:19 +04:00
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
def parse_token(self) -> str:
|
2023-08-08 10:57:41 +04:00
|
|
|
return ''
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
def generate_sec(self) -> str:
|
2023-08-08 10:57:41 +04:00
|
|
|
return 'a:b'
|
2023-05-24 20:03:09 +04:00
|
|
|
|
2023-05-24 17:12:34 +04:00
|
|
|
def generate_sec_part(self) -> str:
|
|
|
|
"""Generates a part for SEC token"""
|
|
|
|
|
2023-05-24 20:03:09 +04:00
|
|
|
return ''.join(
|
|
|
|
secrets.choice(SEC_ALPHABET)
|
|
|
|
for _ in range(11)
|
|
|
|
) + ('0' * 5)
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
def request_cloudflare(
|
|
|
|
self, url: str, method: str,
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
params: Optional[Dict[Any, Any]] = None,
|
|
|
|
data: Optional[Dict[Any, Any]] = None,
|
|
|
|
headers: Optional[Dict[Any, Any]] = None,
|
|
|
|
reqcookies: Optional[Dict[Any, Any]] = None,
|
2022-06-23 15:13:56 +04:00
|
|
|
sendtoken: bool = False,
|
2023-05-29 11:44:19 +04:00
|
|
|
retries: int = 5,
|
2023-08-08 10:57:41 +04:00
|
|
|
timeout: int = 4) -> Any:
|
|
|
|
return None
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def atsession(self) -> str:
|
|
|
|
"""Aternos session cookie,
|
|
|
|
empty string if not logged in
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Session cookie
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self.session.cookies.get(
|
|
|
|
'ATERNOS_SESSION', ''
|
|
|
|
)
|