Add files via upload
This commit is contained in:
parent
c4fa20fd14
commit
b010b8a4c7
8 changed files with 420 additions and 305 deletions
|
@ -0,0 +1,58 @@
|
|||
import hashlib
|
||||
import lxml.html
|
||||
|
||||
from . import atserver
|
||||
from . import atconnect
|
||||
from . import aterrors
|
||||
|
||||
class Client:
|
||||
|
||||
def __init__(self, username, md5=None, password=None):
|
||||
|
||||
if (password == None) and (md5 == None):
|
||||
raise AttributeError('Password was not specified')
|
||||
|
||||
if (password != None):
|
||||
self.__init__(
|
||||
username,
|
||||
md5=hashlib.md5(password.encode('utf-8'))\
|
||||
.hexdigest().lower()
|
||||
)
|
||||
return
|
||||
|
||||
self.atconn = atconnect.AternosConnect()
|
||||
|
||||
self.token = self.atconn.get_token()
|
||||
self.sec = self.atconn.generate_sec()
|
||||
|
||||
self.credentials = {
|
||||
'user': username,
|
||||
'password': md5
|
||||
}
|
||||
|
||||
loginreq = self.atconn.request_cloudflare(
|
||||
f'https://aternos.org/panel/ajax/account/login.php?' + \
|
||||
f'SEC={self.sec}&TOKEN={self.token}',
|
||||
self.atconn.REQPOST, data=self.credentials
|
||||
)
|
||||
|
||||
if loginreq.cookies.get('ATERNOS_SESSION', None) == None:
|
||||
raise aterrors.AternosCredentialsError(
|
||||
'Check your username and password'
|
||||
)
|
||||
|
||||
def get_servers(self):
|
||||
|
||||
serverspage = self.atconn.request_cloudflare(
|
||||
'https://aternos.org/servers/',
|
||||
self.atconn.REQGET
|
||||
)
|
||||
serverstree = lxml.html.fromstring(serverspage.content)
|
||||
serverslist = serverstree.xpath('//div[@class="servers"]/div')
|
||||
|
||||
servers = []
|
||||
for server in serverslist:
|
||||
servid = server.xpath('./div[@class="server-body"]/@data-id')[0]
|
||||
servers.append(atserver.AternosServer(servid, self.atconn))
|
||||
|
||||
return servers
|
|
@ -3,7 +3,8 @@ import time
|
|||
import random
|
||||
import lxml.html
|
||||
from cloudscraper import CloudScraper
|
||||
from aterrors import AternosCredentialsError
|
||||
|
||||
from . import aterrors
|
||||
|
||||
class AternosConnect:
|
||||
|
||||
|
@ -33,7 +34,7 @@ class AternosConnect:
|
|||
pagehead.text_content()
|
||||
)[1]
|
||||
except (IndexError, TypeError):
|
||||
raise AternosCredentialsError(
|
||||
raise aterrors.AternosCredentialsError(
|
||||
'Unable to parse TOKEN from the page'
|
||||
)
|
||||
|
||||
|
|
28
python_aternos/atfiles.py
Normal file
28
python_aternos/atfiles.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from . import atconnect
|
||||
|
||||
class AternosFileManager:
|
||||
|
||||
def __init__(atserv):
|
||||
|
||||
self.atserv = atserv
|
||||
|
||||
def listdir(self, path=''):
|
||||
|
||||
self.atserv.atserver_request(
|
||||
f'https://aternos.org/files/{path}',
|
||||
atconnect.AternosConnect.REQGET
|
||||
)
|
||||
|
||||
def get_file(self, path):
|
||||
|
||||
self.atserv.atserver_request(
|
||||
f'https://aternos.org/panel/ajax/files/download.php?file={path}',
|
||||
atconnect.AternosConnect.REQGET
|
||||
)
|
||||
|
||||
def get_world(self, world):
|
||||
|
||||
self.atserv.atserver_request(
|
||||
f'https://aternos.org/panel/ajax/worlds/download.php?world={world}',
|
||||
atconnect.AternosConnect.REQGET
|
||||
)
|
|
@ -1,5 +1,7 @@
|
|||
import lxml.html
|
||||
import aterrors
|
||||
|
||||
from . import aterrors
|
||||
from . import atfiles
|
||||
|
||||
class AternosServer:
|
||||
|
||||
|
@ -8,7 +10,7 @@ class AternosServer:
|
|||
self.servid = servid
|
||||
self.atconn = atconn
|
||||
|
||||
servreq = self._atserver_request(
|
||||
servreq = self.atserver_request(
|
||||
'https://aternos.org/server',
|
||||
self.atconn.REQGET
|
||||
)
|
||||
|
@ -21,7 +23,12 @@ class AternosServer:
|
|||
'/div[@class="server-info-box-body"]' + \
|
||||
'/div[@class="server-info-box-value"]/span'
|
||||
)
|
||||
self._address = servinfo[0].text
|
||||
|
||||
fullip = servinfo[0].text
|
||||
self._address = fullip
|
||||
self._domain = fullip[:fullip.rfind(':')]
|
||||
self._port = fullip[fullip.rfind(':')+1:]
|
||||
|
||||
self._software = servinfo[1].text
|
||||
self._version = servinfo[2].text
|
||||
|
||||
|
@ -30,7 +37,7 @@ class AternosServer:
|
|||
|
||||
def start(self, accepteula=True):
|
||||
|
||||
startreq = self._atserver_request(
|
||||
startreq = self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/start.php',
|
||||
self.atconn.REQGET, sendtoken=True
|
||||
)
|
||||
|
@ -55,35 +62,46 @@ class AternosServer:
|
|||
f'Unable to start server. Code: {error}'
|
||||
)
|
||||
|
||||
def confirm(self):
|
||||
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/confirm.php',
|
||||
self.atconn.REQGET, sendtoken=True
|
||||
)
|
||||
|
||||
def stop(self):
|
||||
|
||||
self._atserver_request(
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/stop.php',
|
||||
self.atconn.REQGET, sendtoken=True
|
||||
)
|
||||
|
||||
def cancel(self):
|
||||
|
||||
self._atserver_request(
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/cancel.php',
|
||||
self.atconn.REQGET, sendtoken=True
|
||||
)
|
||||
|
||||
def restart(self):
|
||||
|
||||
self._atserver_request(
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/restart.php',
|
||||
self.atconn.REQGET, sendtoken=True
|
||||
)
|
||||
|
||||
def eula(self):
|
||||
|
||||
self._atserver_request(
|
||||
self.atserver_request(
|
||||
'https://aternos.org/panel/ajax/eula.php',
|
||||
self.atconn.REQGET, sendtoken=True
|
||||
)
|
||||
|
||||
def _atserver_request(
|
||||
def files(self):
|
||||
|
||||
return AternosFileManager(self)
|
||||
|
||||
def atserver_request(
|
||||
self, url, method, params=None,
|
||||
data=None, headers=None, sendtoken=False):
|
||||
|
||||
|
@ -101,6 +119,14 @@ class AternosServer:
|
|||
def address(self):
|
||||
return self._address
|
||||
|
||||
@property
|
||||
def domain(self):
|
||||
return self._domain
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
return self._port
|
||||
|
||||
@property
|
||||
def software(self):
|
||||
return self._software
|
||||
|
|
4
setup.py
4
setup.py
|
@ -5,7 +5,7 @@ with open('README.md', 'rt') as readme:
|
|||
|
||||
setuptools.setup(
|
||||
name='python-aternos',
|
||||
version='0.1',
|
||||
version='0.2',
|
||||
author='Chechkenev Andrey (@DarkCat09)',
|
||||
author_email='aacd0709@mail.ru',
|
||||
description='An unofficial Aternos API',
|
||||
|
@ -14,6 +14,7 @@ setuptools.setup(
|
|||
url='https://github.com/DarkCat09/python-aternos',
|
||||
project_urls={
|
||||
'Bug Tracker': 'https://github.com/DarkCat09/python-aternos/issues',
|
||||
'Documentation': 'https://github.com/DarkCat09/python-aternos/wiki/Client-(entry-point)',
|
||||
},
|
||||
classifiers=[
|
||||
'Programming Language :: Python :: 3',
|
||||
|
@ -25,5 +26,6 @@ setuptools.setup(
|
|||
'requests==2.25.1',
|
||||
'cloudscraper==1.2.58'
|
||||
],
|
||||
packages=['python_aternos'],
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
|
|
Reference in a new issue