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/examples/console_example.py

38 lines
802 B
Python
Raw Normal View History

import asyncio
import aioconsole
from getpass import getpass
from python_aternos import Client, atwss
user = input('Username: ')
pswd = getpass('Password: ')
resp = input('Show responses? ').upper() == 'Y'
aternos = Client.from_credentials(user, pswd)
s = aternos.list_servers()[0]
socket = s.wss()
if resp:
@socket.wssreceiver(atwss.Streams.console)
async def console(msg):
print('<', msg)
async def main():
s.start()
await asyncio.gather(
socket.connect(),
commands()
)
async def commands():
while True:
cmd = await aioconsole.ainput('> ')
if cmd.strip() == '':
continue
await socket.send({
'stream': 'console',
'type': 'command',
'data': cmd
})
asyncio.run(main())