Account actions, session, examples and readme

This commit is contained in:
DarkCat09 2022-04-01 17:00:02 +04:00
parent 75b10e6e8c
commit 03ca4098bc
8 changed files with 155 additions and 62 deletions

38
examples/files_example.py Normal file
View file

@ -0,0 +1,38 @@
from getpass import getpass
from python_aternos import Client, atserver
user = input('Username: ')
pswd = getpass('Password: ')
aternos = Client.from_credentials(user, pswd)
s = aternos.list_servers()[0]
files = s.files()
while True:
cmd = input('> ').strip().lower()
if cmd == 'help':
print(
'''Commands list:
help - show this message
quit - exit from the script
world - download the world
list [path] - show directory (or root) contents'''
)
if cmd == 'quit':
break
if cmd.startswith('list'):
path = cmd.removeprefix('list').strip()
directory = files.listdir(path)
print(path, 'contains:')
for file in directory:
print('\t' + file.name)
if cmd == 'world':
file = files.get_file('/world')
with open('world.zip', 'wb') as f:
f.write(file.get_content())

18
examples/info_example.py Normal file
View file

@ -0,0 +1,18 @@
from getpass import getpass
from python_aternos import Client, atserver
user = input('Username: ')
pswd = getpass('Password: ')
aternos = Client.from_credentials(user, pswd)
srvs = aternos.list_servers()
for srv in srvs:
print('*** ' + srv.domain + ' ***')
print(srv.motd)
print('*** Status:', srv.status)
print('*** Full address:', srv.address)
print('*** Port:', srv.port)
print('*** Name:', srv.subdomain)
print('*** Minecraft:', srv.software, srv.version)
print('*** IsBedrock:', srv.edition == atserver.Edition.bedrock)
print('*** IsJava:', srv.edition == atserver.Edition.java)

View file

@ -5,7 +5,7 @@ user = input('Username: ')
pswd = getpass('Password: ')
aternos = Client.from_credentials(user, pswd)
srvs = aternos.servers
srvs = aternos.list_servers()
print(srvs)
s = srvs[0]

View file

@ -0,0 +1,15 @@
from getpass import getpass
from python_aternos import Client, atwss
user = input('Username: ')
pswd = getpass('Password: ')
aternos = Client.from_credentials(user, pswd)
s = aternos.list_servers()[0]
socket = s.wss()
@socket.wssreceiver(atwss.Streams.console)
def console(msg):
print('Received: ' + msg)
s.start()