Bugfixes in FilesAPI, logging and unittest
This commit is contained in:
parent
cec2938804
commit
75b10e6e8c
6 changed files with 58 additions and 31 deletions
|
@ -1,6 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import random
|
import random
|
||||||
|
import logging
|
||||||
import lxml.html
|
import lxml.html
|
||||||
from requests import Response
|
from requests import Response
|
||||||
from cloudscraper import CloudScraper
|
from cloudscraper import CloudScraper
|
||||||
|
@ -16,6 +16,7 @@ class AternosConnect:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
||||||
self.session = CloudScraper()
|
self.session = CloudScraper()
|
||||||
|
self.atsession = ''
|
||||||
|
|
||||||
def parse_token(self) -> str:
|
def parse_token(self) -> str:
|
||||||
|
|
||||||
|
@ -91,10 +92,18 @@ class AternosConnect:
|
||||||
headers:Optional[dict]=None, reqcookies:Optional[dict]=None,
|
headers:Optional[dict]=None, reqcookies:Optional[dict]=None,
|
||||||
sendtoken:bool=False, redirect:bool=True) -> Response:
|
sendtoken:bool=False, redirect:bool=True) -> Response:
|
||||||
|
|
||||||
params = params if params else {}
|
try:
|
||||||
data = data if data else {}
|
self.atsession = self.session.cookies['ATERNOS_SESSION']
|
||||||
headers = headers if headers else {}
|
except KeyError:
|
||||||
reqcookies = reqcookies if reqcookies else {}
|
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
|
headers['User-Agent'] = REQUA
|
||||||
|
|
||||||
if sendtoken:
|
if sendtoken:
|
||||||
|
@ -102,8 +111,15 @@ class AternosConnect:
|
||||||
params['SEC'] = self.sec
|
params['SEC'] = self.sec
|
||||||
|
|
||||||
# requests.cookies.CookieConflictError bugfix
|
# requests.cookies.CookieConflictError bugfix
|
||||||
reqcookies['ATERNOS_SESSION'] = self.session.cookies['ATERNOS_SESSION']
|
reqcookies['ATERNOS_SESSION'] = self.atsession
|
||||||
del self.session.cookies['ATERNOS_SESSION']
|
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':
|
if method == 'POST':
|
||||||
req = self.session.post(
|
req = self.session.post(
|
||||||
|
@ -117,5 +133,12 @@ class AternosConnect:
|
||||||
headers=headers, cookies=reqcookies,
|
headers=headers, cookies=reqcookies,
|
||||||
allow_redirects=redirect
|
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
|
return req
|
||||||
|
|
|
@ -20,7 +20,7 @@ class AternosFile:
|
||||||
size:Union[int,float]=0) -> None:
|
size:Union[int,float]=0) -> None:
|
||||||
|
|
||||||
self.atserv = atserv
|
self.atserv = atserv
|
||||||
self._path = path
|
self._path = path.lstrip('/')
|
||||||
self._name = name
|
self._name = name
|
||||||
self._full = path + name
|
self._full = path + name
|
||||||
self._ftype = ftype
|
self._ftype = ftype
|
||||||
|
@ -59,7 +59,7 @@ class AternosFile:
|
||||||
def get_text(self) -> str:
|
def get_text(self) -> str:
|
||||||
|
|
||||||
editor = self.atserv.atserver_request(
|
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)
|
edittree = lxml.html.fromstring(editor.content)
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,12 @@ class FileManager:
|
||||||
|
|
||||||
def listdir(self, path:str='') -> List[AternosFile]:
|
def listdir(self, path:str='') -> List[AternosFile]:
|
||||||
|
|
||||||
|
path = path.lstrip('/')
|
||||||
filesreq = self.atserv.atserver_request(
|
filesreq = self.atserv.atserver_request(
|
||||||
f'https://aternos.org/files/{path}', 'GET'
|
f'https://aternos.org/files/{path}', 'GET'
|
||||||
)
|
)
|
||||||
filestree = lxml.html.fromstring(filesreq.content)
|
filestree = lxml.html.fromstring(filesreq.content)
|
||||||
fileslist = filestree.xpath('//div[@class="file clickable"]')
|
fileslist = filestree.xpath('//div[contains(concat(" ",normalize-space(@class)," ")," file ")]')
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
for f in fileslist:
|
for f in fileslist:
|
||||||
|
@ -29,7 +30,6 @@ class FileManager:
|
||||||
else FileType.directory
|
else FileType.directory
|
||||||
|
|
||||||
fsize_raw = f.xpath('./div[@class="filesize"]')
|
fsize_raw = f.xpath('./div[@class="filesize"]')
|
||||||
print(fsize_raw)
|
|
||||||
fsize = 0
|
fsize = 0
|
||||||
if len(fsize_raw) > 0:
|
if len(fsize_raw) > 0:
|
||||||
|
|
||||||
|
@ -64,10 +64,9 @@ class FileManager:
|
||||||
'GB': 1000000000
|
'GB': 1000000000
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
result = num * measure_match[measure]
|
return num * measure_match[measure]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
result = -1
|
return -1
|
||||||
return result
|
|
||||||
|
|
||||||
def get_file(self, path:str) -> Union[AternosFile,None]:
|
def get_file(self, path:str) -> Union[AternosFile,None]:
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,13 @@ class AternosServer:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, servid:str,
|
self, servid:str,
|
||||||
atconn:AternosConnect) -> None:
|
atconn:AternosConnect,
|
||||||
|
reqinfo:bool=True) -> None:
|
||||||
|
|
||||||
self.servid = servid
|
self.servid = servid
|
||||||
self.atconn = atconn
|
self.atconn = atconn
|
||||||
|
if reqinfo:
|
||||||
|
self.fetch()
|
||||||
|
|
||||||
def fetch(self) -> None:
|
def fetch(self) -> None:
|
||||||
|
|
||||||
|
|
|
@ -8,28 +8,29 @@ class TestJs2Py(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
|
|
||||||
self.tests = []
|
self.tests = []
|
||||||
with open('../token.txt', 'rt') as f:
|
with open('token.txt', 'rt') as f:
|
||||||
lines = re.split(r'[\r\n]', f.read())
|
lines = re.split(r'[\r\n]', f.read())
|
||||||
del lines[len(lines)-1] # Remove empty string
|
del lines[len(lines)-1] # Remove empty string
|
||||||
self.tests = lines
|
self.tests = lines
|
||||||
|
|
||||||
self.results = [
|
self.results = [
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2rKOA1IFdBcHhEM616cb'
|
'2rKOA1IFdBcHhEM616cb',
|
||||||
'2iXh5W5uEYq5fWJIazQ6'
|
'2iXh5W5uEYq5fWJIazQ6',
|
||||||
'CuUcmZ27Fb8bVBNw12Vj'
|
'CuUcmZ27Fb8bVBNw12Vj',
|
||||||
'YPPe8Ph7vzYaZ9PF9oQP'
|
'YPPe8Ph7vzYaZ9PF9oQP',
|
||||||
'UfLlemvKEE16ltk0hZNM'
|
'UfLlemvKEE16ltk0hZNM',
|
||||||
'q6pYdP6r7xiVHhbotvlN'
|
'q6pYdP6r7xiVHhbotvlN',
|
||||||
'q6pYdP6r7xiVHhbotvlN'
|
'q6pYdP6r7xiVHhbotvlN',
|
||||||
'XAIbksgkVX9JYboMDI7D'
|
'XAIbksgkVX9JYboMDI7D',
|
||||||
|
'sBImgVg6RL98W1khPYMl'
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_base64(self) -> None:
|
def test_base64(self) -> None:
|
||||||
|
|
|
@ -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[["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["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[["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");})();
|
||||||
|
|
Reference in a new issue