This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
python-aternos/python_aternos/atconnect.py

63 lines
1.5 KiB
Python
Raw Normal View History

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
class AternosConnect:
2022-09-29 18:18:15 +04:00
"""Class for sending API requests,
bypassing Cloudflare and parsing responses"""
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 = ''
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 17:12:34 +04:00
def generate_sec_part(self) -> str:
"""Generates a part for SEC token"""
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,
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,
retries: int = 5,
2023-08-08 10:57:41 +04:00
timeout: int = 4) -> Any:
return None
@property
def atsession(self) -> str:
"""Aternos session cookie,
empty string if not logged in
Returns:
Session cookie
"""
return self.session.cookies.get(
'ATERNOS_SESSION', ''
)