Bugfixes in FilesAPI, logging and unittest

This commit is contained in:
DarkCat09 2022-03-30 19:40:58 +04:00
parent cec2938804
commit 75b10e6e8c
6 changed files with 58 additions and 31 deletions

View file

@ -1,6 +1,6 @@
import re
import time
import random
import logging
import lxml.html
from requests import Response
from cloudscraper import CloudScraper
@ -16,6 +16,7 @@ class AternosConnect:
def __init__(self) -> None:
self.session = CloudScraper()
self.atsession = ''
def parse_token(self) -> str:
@ -91,10 +92,18 @@ class AternosConnect:
headers:Optional[dict]=None, reqcookies:Optional[dict]=None,
sendtoken:bool=False, redirect:bool=True) -> Response:
params = params if params else {}
data = data if data else {}
headers = headers if headers else {}
reqcookies = reqcookies if reqcookies else {}
try:
self.atsession = self.session.cookies['ATERNOS_SESSION']
except KeyError:
pass
if method not in ('GET', 'POST'):
raise NotImplementedError('Only GET and POST are available')
params = params or {}
data = data or {}
headers = headers or {}
reqcookies = reqcookies or {}
headers['User-Agent'] = REQUA
if sendtoken:
@ -102,8 +111,15 @@ class AternosConnect:
params['SEC'] = self.sec
# requests.cookies.CookieConflictError bugfix
reqcookies['ATERNOS_SESSION'] = self.session.cookies['ATERNOS_SESSION']
reqcookies['ATERNOS_SESSION'] = self.atsession
del self.session.cookies['ATERNOS_SESSION']
logging.debug(f'Requesting({method})' + url)
logging.debug('headers=' + str(headers))
logging.debug('params=' + str(params))
logging.debug('data=' + str(data))
logging.debug('req-cookies=' + str(reqcookies))
logging.debug('session-cookies=' + str(self.session.cookies))
if method == 'POST':
req = self.session.post(
@ -117,5 +133,12 @@ class AternosConnect:
headers=headers, cookies=reqcookies,
allow_redirects=redirect
)
logging.info(
f'{method} completed with {req.status_code} status'
)
with open('debug.html', 'wb') as f:
f.write(req.content)
return req

View file

@ -20,7 +20,7 @@ class AternosFile:
size:Union[int,float]=0) -> None:
self.atserv = atserv
self._path = path
self._path = path.lstrip('/')
self._name = name
self._full = path + name
self._ftype = ftype
@ -59,7 +59,7 @@ class AternosFile:
def get_text(self) -> str:
editor = self.atserv.atserver_request(
f'https://aternos.org/files/{self._name}', 'GET'
f'https://aternos.org/files/{self._full}', 'GET'
)
edittree = lxml.html.fromstring(editor.content)

View file

@ -14,11 +14,12 @@ class FileManager:
def listdir(self, path:str='') -> List[AternosFile]:
path = path.lstrip('/')
filesreq = self.atserv.atserver_request(
f'https://aternos.org/files/{path}', 'GET'
)
filestree = lxml.html.fromstring(filesreq.content)
fileslist = filestree.xpath('//div[@class="file clickable"]')
fileslist = filestree.xpath('//div[contains(concat(" ",normalize-space(@class)," ")," file ")]')
files = []
for f in fileslist:
@ -29,7 +30,6 @@ class FileManager:
else FileType.directory
fsize_raw = f.xpath('./div[@class="filesize"]')
print(fsize_raw)
fsize = 0
if len(fsize_raw) > 0:
@ -64,10 +64,9 @@ class FileManager:
'GB': 1000000000
}
try:
result = num * measure_match[measure]
return num * measure_match[measure]
except KeyError:
result = -1
return result
return -1
def get_file(self, path:str) -> Union[AternosFile,None]:

View file

@ -27,10 +27,13 @@ class AternosServer:
def __init__(
self, servid:str,
atconn:AternosConnect) -> None:
atconn:AternosConnect,
reqinfo:bool=True) -> None:
self.servid = servid
self.atconn = atconn
if reqinfo:
self.fetch()
def fetch(self) -> None:

View file

@ -8,28 +8,29 @@ class TestJs2Py(unittest.TestCase):
def setUp(self) -> None:
self.tests = []
with open('../token.txt', 'rt') as f:
with open('token.txt', 'rt') as f:
lines = re.split(r'[\r\n]', f.read())
del lines[len(lines)-1] # Remove empty string
self.tests = lines
self.results = [
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2rKOA1IFdBcHhEM616cb'
'2iXh5W5uEYq5fWJIazQ6'
'CuUcmZ27Fb8bVBNw12Vj'
'YPPe8Ph7vzYaZ9PF9oQP'
'UfLlemvKEE16ltk0hZNM'
'q6pYdP6r7xiVHhbotvlN'
'q6pYdP6r7xiVHhbotvlN'
'XAIbksgkVX9JYboMDI7D'
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2rKOA1IFdBcHhEM616cb',
'2iXh5W5uEYq5fWJIazQ6',
'CuUcmZ27Fb8bVBNw12Vj',
'YPPe8Ph7vzYaZ9PF9oQP',
'UfLlemvKEE16ltk0hZNM',
'q6pYdP6r7xiVHhbotvlN',
'q6pYdP6r7xiVHhbotvlN',
'XAIbksgkVX9JYboMDI7D',
'sBImgVg6RL98W1khPYMl'
]
def test_base64(self) -> None:

View file

@ -14,3 +14,4 @@
(() => {window[["AJA","X_T","OKEN"].join('')]=window['document']&&window[("Map")]&&window[("se" + "tTi" + "meo" + "u" + "t")]?["Ew9q","VIepR","GRX","S1Oban9U"].reverse().join(''):"q6pYdP6r7xiVHhbotvlN";})();
(() => {window["AJAX_TOKEN"]=window['document']&&window["Map"]&&window[["out","e","Tim","et","s"].reverse().join('')]?["pREw9q","XVIe","UGR","S1Oban9"].reverse().join(''):["dYp6q","Vix7r6P","tobhH","Nlv"].map(s => s.split('').reverse().join('')).join('');})();
(() => {window[["OKEN", "T", "_", "AJAX"].reverse().join("")] = window["document"] && window["Map"] && window["set" + "T" + "im" + "e" + "o" + "u" + "t"] ? ["DYK", "OWD1TyD", "TJ", "JtNpZ", "MhW"].map((s) => s.split("").reverse().join("")).join("") : "XAIbksgkVX9JYboMDI7D";})();
(() => {window[["XAJA","T_","NEKO"].map(s => s.split('').reverse().join('')).join('')]=window['document']&&window[["ap","M"].reverse().join('')]&&window[["es","iTt","oem","u","t"].map(s => s.split('').reverse().join('')).join('')]?["Kk1LG02","If8J","lZPFwRqIG"].reverse().join(''):("sBI" + "mgV" + "g6RL98W1" + "khPY" + "Ml");})();