BASE_URL constants
This commit is contained in:
parent
345ba7e6ed
commit
9d3de01395
9 changed files with 71 additions and 52 deletions
|
@ -13,8 +13,10 @@ from typing import Optional, Type
|
|||
|
||||
import lxml.html
|
||||
|
||||
from .atserver import AternosServer
|
||||
from .atconnect import AternosConnect
|
||||
from .atconnect import BASE_URL, AJAX_URL
|
||||
|
||||
from .atserver import AternosServer
|
||||
from .aterrors import CredentialsError
|
||||
from .aterrors import TwoFactorAuthError
|
||||
|
||||
|
@ -110,7 +112,7 @@ class Client:
|
|||
credentials['code'] = str(code)
|
||||
|
||||
loginreq = atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/login.php',
|
||||
f'{AJAX_URL}/account/login.php',
|
||||
'POST', data=credentials, sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -343,7 +345,7 @@ class Client:
|
|||
return self.servers
|
||||
|
||||
serverspage = self.atconn.request_cloudflare(
|
||||
'https://aternos.org/servers/', 'GET'
|
||||
f'{BASE_URL}/servers/', 'GET'
|
||||
)
|
||||
serverstree = lxml.html.fromstring(serverspage.content)
|
||||
|
||||
|
@ -396,7 +398,7 @@ class Client:
|
|||
"""Log out from Aternos account"""
|
||||
|
||||
self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/logout.php',
|
||||
f'{AJAX_URL}/account/logout.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -410,7 +412,7 @@ class Client:
|
|||
"""
|
||||
|
||||
self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/username.php',
|
||||
f'{AJAX_URL}/account/username.php',
|
||||
'POST', data={'username': value}, sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -432,7 +434,7 @@ class Client:
|
|||
raise ValueError('Invalid e-mail!')
|
||||
|
||||
self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/email.php',
|
||||
f'{AJAX_URL}/account/email.php',
|
||||
'POST', data={'email': value}, sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -460,7 +462,7 @@ class Client:
|
|||
"""
|
||||
|
||||
self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/password.php',
|
||||
f'{AJAX_URL}/account/password.php',
|
||||
'POST', data={
|
||||
'oldpassword': old,
|
||||
'newpassword': new,
|
||||
|
@ -472,7 +474,7 @@ class Client:
|
|||
a QR code for enabling 2FA"""
|
||||
|
||||
return self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/secret.php',
|
||||
f'{AJAX_URL}/account/secret.php',
|
||||
'GET', sendtoken=True
|
||||
).json()
|
||||
|
||||
|
@ -499,7 +501,7 @@ class Client:
|
|||
"""
|
||||
|
||||
self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/twofactor.php',
|
||||
f'{AJAX_URL}/account/twofactor.php',
|
||||
'POST', data={
|
||||
'code': code
|
||||
}, sendtoken=True
|
||||
|
@ -513,7 +515,7 @@ class Client:
|
|||
"""
|
||||
|
||||
self.atconn.request_cloudflare(
|
||||
'https://aternos.org/panel/ajax/account/disbaleTwofactor.php',
|
||||
f'{AJAX_URL}/account/disbaleTwofactor.php',
|
||||
'POST', data={
|
||||
'code': code
|
||||
}, sendtoken=True
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Modifying server and world options"""
|
||||
|
||||
# TODO: Still needs refactoring
|
||||
|
||||
import enum
|
||||
import re
|
||||
|
||||
|
@ -8,9 +10,11 @@ from typing import TYPE_CHECKING
|
|||
|
||||
import lxml.html
|
||||
|
||||
from .atconnect import BASE_URL, AJAX_URL
|
||||
if TYPE_CHECKING:
|
||||
from .atserver import AternosServer
|
||||
|
||||
|
||||
DAT_PREFIX = 'Data:'
|
||||
DAT_GR_PREFIX = 'Data:GameRules:'
|
||||
|
||||
|
@ -111,11 +115,12 @@ class Difficulty(enum.IntEnum):
|
|||
|
||||
# checking timezone format
|
||||
tzcheck = re.compile(r'(^[A-Z]\w+\/[A-Z]\w+$)|^UTC$')
|
||||
|
||||
# options types converting
|
||||
convert = {
|
||||
'config-option-number': int,
|
||||
'config-option-select': int,
|
||||
'config-option-toggle': bool
|
||||
'config-option-toggle': bool,
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,7 +146,7 @@ class AternosConfig:
|
|||
"""
|
||||
|
||||
optreq = self.atserv.atserver_request(
|
||||
'https://aternos.org/options', 'GET'
|
||||
f'{BASE_URL}/options', 'GET'
|
||||
)
|
||||
opttree = lxml.html.fromstring(optreq)
|
||||
|
||||
|
@ -169,7 +174,7 @@ class AternosConfig:
|
|||
)
|
||||
|
||||
self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/timezone.php',
|
||||
f'{AJAX_URL}/timezone.php',
|
||||
'POST', data={'timezone': value},
|
||||
sendtoken=True
|
||||
)
|
||||
|
@ -182,7 +187,7 @@ class AternosConfig:
|
|||
"""
|
||||
|
||||
optreq = self.atserv.atserver_request(
|
||||
'https://aternos.org/options', 'GET'
|
||||
f'{BASE_URL}/options', 'GET'
|
||||
)
|
||||
opttree = lxml.html.fromstring(optreq)
|
||||
imgopt = opttree.xpath(
|
||||
|
@ -203,7 +208,7 @@ class AternosConfig:
|
|||
"""
|
||||
|
||||
self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/image.php',
|
||||
f'{AJAX_URL}/image.php',
|
||||
'POST', data={'image': f'openjdk:{value}'},
|
||||
sendtoken=True
|
||||
)
|
||||
|
@ -238,7 +243,7 @@ class AternosConfig:
|
|||
`server.properties` dictionary
|
||||
"""
|
||||
|
||||
return self.__get_all_props('https://aternos.org/options', proptyping)
|
||||
return self.__get_all_props(f'{BASE_URL}/options', proptyping)
|
||||
|
||||
def set_server_props(self, props: Dict[str, Any]) -> None:
|
||||
"""Updates server.properties options with the given dict
|
||||
|
@ -296,7 +301,7 @@ class AternosConfig:
|
|||
"""
|
||||
|
||||
return self.__get_all_props(
|
||||
f'https://aternos.org/files/{world}/level.dat',
|
||||
f'{BASE_URL}/files/{world}/level.dat',
|
||||
proptyping, [DAT_PREFIX, DAT_GR_PREFIX]
|
||||
)
|
||||
|
||||
|
@ -327,7 +332,7 @@ class AternosConfig:
|
|||
def __set_prop(self, file: str, option: str, value: Any) -> None:
|
||||
|
||||
self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/config.php',
|
||||
f'{AJAX_URL}/config.php',
|
||||
'POST', data={
|
||||
'file': file,
|
||||
'option': option,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Stores API connection session and sends requests"""
|
||||
"""Stores API session and sends requests"""
|
||||
|
||||
import re
|
||||
import time
|
||||
|
@ -22,6 +22,10 @@ from .aterrors import TokenError
|
|||
from .aterrors import CloudflareError
|
||||
from .aterrors import AternosPermissionError
|
||||
|
||||
|
||||
BASE_URL = 'https://aternos.org'
|
||||
AJAX_URL = f'{BASE_URL}/ajax'
|
||||
|
||||
REQUA = \
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' \
|
||||
'(KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.47'
|
||||
|
@ -94,7 +98,7 @@ class AternosConnect:
|
|||
"""
|
||||
|
||||
loginpage = self.request_cloudflare(
|
||||
'https://aternos.org/go/', 'GET'
|
||||
f'{BASE_URL}/go/', 'GET'
|
||||
).content
|
||||
|
||||
# Using the standard string methods
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing import TYPE_CHECKING
|
|||
|
||||
import lxml.html
|
||||
|
||||
from .atconnect import BASE_URL, AJAX_URL
|
||||
from .aterrors import FileError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -87,7 +88,7 @@ class AternosFile:
|
|||
|
||||
name = name.strip().replace('/', '_')
|
||||
req = self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/files/create.php',
|
||||
f'{AJAX_URL}/files/create.php',
|
||||
'POST', data={
|
||||
'file': f'{self._path}/{name}',
|
||||
'type': 'file'
|
||||
|
@ -114,7 +115,7 @@ class AternosFile:
|
|||
)
|
||||
|
||||
req = self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/delete.php',
|
||||
f'{AJAX_URL}/delete.php',
|
||||
'POST', data={'file': self._path},
|
||||
sendtoken=True
|
||||
)
|
||||
|
@ -140,7 +141,7 @@ class AternosFile:
|
|||
)
|
||||
|
||||
file = self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/files/download.php',
|
||||
f'{AJAX_URL}/files/download.php',
|
||||
'GET', params={
|
||||
'file': self._path
|
||||
}
|
||||
|
@ -165,7 +166,7 @@ class AternosFile:
|
|||
"""
|
||||
|
||||
req = self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/save.php',
|
||||
f'{AJAX_URL}/save.php',
|
||||
'POST', data={
|
||||
'file': self._path,
|
||||
'content': value
|
||||
|
@ -200,7 +201,7 @@ class AternosFile:
|
|||
|
||||
filepath = self._path.lstrip("/")
|
||||
editor = self.atserv.atserver_request(
|
||||
f'https://aternos.org/files/{filepath}', 'GET'
|
||||
f'{BASE_URL}/files/{filepath}', 'GET'
|
||||
)
|
||||
edittree = lxml.html.fromstring(editor.content)
|
||||
editblock = edittree.xpath('//div[@id="editor"]')
|
||||
|
|
|
@ -5,7 +5,9 @@ from typing import TYPE_CHECKING
|
|||
|
||||
import lxml.html
|
||||
|
||||
from .atconnect import BASE_URL, AJAX_URL
|
||||
from .atfile import AternosFile, FileType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .atserver import AternosServer
|
||||
|
||||
|
@ -41,7 +43,7 @@ class FileManager:
|
|||
path = path.lstrip('/')
|
||||
|
||||
filesreq = self.atserv.atserver_request(
|
||||
f'https://aternos.org/files/{path}', 'GET'
|
||||
f'{BASE_URL}/files/{path}', 'GET'
|
||||
)
|
||||
filestree = lxml.html.fromstring(filesreq.content)
|
||||
|
||||
|
@ -163,7 +165,7 @@ class FileManager:
|
|||
"""
|
||||
|
||||
file = self.atserv.atserver_request( # type: ignore
|
||||
'https://aternos.org/panel/ajax/files/download.php'
|
||||
f'{AJAX_URL}/files/download.php'
|
||||
'GET', params={
|
||||
'file': path.replace('/', '%2F')
|
||||
}
|
||||
|
@ -183,7 +185,7 @@ class FileManager:
|
|||
"""
|
||||
|
||||
resp = self.atserv.atserver_request( # type: ignore
|
||||
'https://aternos.org/panel/ajax/worlds/download.php'
|
||||
f'{AJAX_URL}/worlds/download.php'
|
||||
'GET', params={
|
||||
'world': world.replace('/', '%2F')
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing import TYPE_CHECKING
|
|||
|
||||
import lxml.html
|
||||
|
||||
from .atconnect import BASE_URL, AJAX_URL
|
||||
if TYPE_CHECKING:
|
||||
from .atserver import AternosServer
|
||||
|
||||
|
@ -73,7 +74,7 @@ class PlayersList:
|
|||
return self.players
|
||||
|
||||
listreq = self.atserv.atserver_request(
|
||||
f'https://aternos.org/players/{self.lst.value}',
|
||||
f'{BASE_URL}/players/{self.lst.value}',
|
||||
'GET'
|
||||
)
|
||||
listtree = lxml.html.fromstring(listreq.content)
|
||||
|
@ -98,7 +99,7 @@ class PlayersList:
|
|||
"""
|
||||
|
||||
self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/players/add.php',
|
||||
f'{AJAX_URL}/players/add.php',
|
||||
'POST', data={
|
||||
'list': self.lst.value,
|
||||
'name': name
|
||||
|
@ -115,7 +116,7 @@ class PlayersList:
|
|||
"""
|
||||
|
||||
self.atserv.atserver_request(
|
||||
'https://aternos.org/panel/ajax/players/remove.php',
|
||||
f'{AJAX_URL}/players/remove.php',
|
||||
'POST', data={
|
||||
'list': self.lst.value,
|
||||
'name': name
|
||||
|
|
|
@ -8,13 +8,17 @@ from typing import List, Dict, Any
|
|||
|
||||
import requests
|
||||
|
||||
from .atconnect import AJAX_URL
|
||||
from .atconnect import AternosConnect
|
||||
from .aterrors import ServerStartError
|
||||
from .atfm import FileManager
|
||||
from .atconf import AternosConfig
|
||||
from .atwss import AternosWss
|
||||
|
||||
from .atplayers import PlayersList
|
||||
from .atplayers import Lists
|
||||
from .atwss import AternosWss
|
||||
|
||||
from .atfm import FileManager
|
||||
from .atconf import AternosConfig
|
||||
|
||||
from .aterrors import ServerStartError
|
||||
|
||||
|
||||
class Edition(enum.IntEnum):
|
||||
|
@ -72,7 +76,7 @@ class AternosServer:
|
|||
"""Send a request to Aternos API to get all server info"""
|
||||
|
||||
servreq = self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/status.php',
|
||||
f'{AJAX_URL}/status.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
self._info = json.loads(servreq.content)
|
||||
|
@ -112,7 +116,7 @@ class AternosServer:
|
|||
"""
|
||||
|
||||
startreq = self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/start.php',
|
||||
f'{AJAX_URL}/start.php',
|
||||
'GET', params={'headstart': int(headstart)},
|
||||
sendtoken=True
|
||||
)
|
||||
|
@ -134,7 +138,7 @@ class AternosServer:
|
|||
"""Confirms server launching"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/confirm.php',
|
||||
f'{AJAX_URL}/confirm.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -142,7 +146,7 @@ class AternosServer:
|
|||
"""Stops the server"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/stop.php',
|
||||
f'{AJAX_URL}/stop.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -150,7 +154,7 @@ class AternosServer:
|
|||
"""Cancels server launching"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/cancel.php',
|
||||
f'{AJAX_URL}/cancel.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -158,7 +162,7 @@ class AternosServer:
|
|||
"""Restarts the server"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/restart.php',
|
||||
f'{AJAX_URL}/restart.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -166,7 +170,7 @@ class AternosServer:
|
|||
"""Accepts the Mojang EULA"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/eula.php',
|
||||
f'{AJAX_URL}/eula.php',
|
||||
'GET', sendtoken=True
|
||||
)
|
||||
|
||||
|
@ -259,7 +263,7 @@ class AternosServer:
|
|||
"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/options/subdomain.php',
|
||||
f'{AJAX_URL}/options/subdomain.php',
|
||||
'GET', params={'subdomain': value},
|
||||
sendtoken=True
|
||||
)
|
||||
|
@ -285,7 +289,7 @@ class AternosServer:
|
|||
"""
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/options/motd.php',
|
||||
f'{AJAX_URL}/options/motd.php',
|
||||
'POST', data={'motd': value},
|
||||
sendtoken=True
|
||||
)
|
||||
|
|
|
@ -39,7 +39,7 @@ errored = []
|
|||
def get_code() -> bool:
|
||||
|
||||
r = conn.request_cloudflare(
|
||||
'https://aternos.org/go', 'GET'
|
||||
f'{BASE_URL}/go', 'GET'
|
||||
)
|
||||
if r.status_code != 200:
|
||||
print(r.status_code)
|
||||
|
|
|
@ -6,27 +6,27 @@ mock = Mocker()
|
|||
with mock:
|
||||
|
||||
mock.get(
|
||||
'https://aternos.org/go/',
|
||||
f'{BASE_URL}/go/',
|
||||
content=files.read_html('aternos_go'),
|
||||
)
|
||||
|
||||
mock.get(
|
||||
'https://aternos.org/servers/',
|
||||
f'{BASE_URL}/servers/',
|
||||
content=files.read_html('aternos_servers'),
|
||||
)
|
||||
|
||||
mock.get(
|
||||
'https://aternos.org/server/',
|
||||
f'{BASE_URL}/server/',
|
||||
content=files.read_html('aternos_server1'),
|
||||
)
|
||||
|
||||
mock.get(
|
||||
'https://aternos.org/panel/ajax/status.php',
|
||||
f'{AJAX_URL}/status.php',
|
||||
content=files.read_html('aternos_status'),
|
||||
)
|
||||
|
||||
mock.post(
|
||||
'https://aternos.org/panel/ajax/account/login.php',
|
||||
f'{AJAX_URL}/account/login.php',
|
||||
json={
|
||||
'success': True,
|
||||
'error': None,
|
||||
|
@ -39,11 +39,11 @@ with mock:
|
|||
)
|
||||
|
||||
mock.get(
|
||||
'https://aternos.org/players/',
|
||||
f'{BASE_URL}/players/',
|
||||
content=files.read_html('aternos_players'),
|
||||
)
|
||||
|
||||
mock.get(
|
||||
'https://aternos.org/files/',
|
||||
f'{BASE_URL}/files/',
|
||||
content=files.read_html('aternos_file_root'),
|
||||
)
|
||||
|
|
Reference in a new issue