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/atplayers.py

54 lines
1.2 KiB
Python
Raw Normal View History

import lxml.html
from typing import List
2021-10-15 19:31:47 +04:00
from typing import TYPE_CHECKING
from . import atconnect
2021-10-15 19:31:47 +04:00
if TYPE_CHECKING:
from atserver import AternosServer
class AternosPlayersList:
2021-10-15 19:31:47 +04:00
def __init__(self, lst:str, atserv:'AternosServer') -> None:
self.atserv = atserv
self.lst = lst
def add(self, name:str) -> None:
self.atserv.atserver_request(
'https://aternos.org/panel/ajax/players/add.php',
atconnect.REQPOST, data={
'list': self.lst,
'name': name
}
)
def remove(self, name:str) -> None:
self.atserv.atserver_request(
'https://aternos.org/panel/ajax/players/remove.php',
atconnect.REQPOST, data={
'list': self.lst,
'name': name
}
)
@property
def players(self) -> List[str]:
listreq = atserv.atserver_request(
f'https://aternos.org/players/{lst}',
atconnect.REQGET
)
listtree = lxml.html.fromstring(listreq.content)
items = listtree.xpath(
'//div[@class="player-list"]' + \
'/div[@class="list-item-container"]' + \
'/div[@class="list-item"]'
)
result = []
for i in items:
name = i.xpath('./div[@class="list-name"]')
result.append(name)