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

35 lines
682 B
Python
Raw Normal View History

2022-05-18 18:35:46 +03:00
import asyncio
import logging
2022-05-18 18:35:46 +03:00
from getpass import getpass
from python_aternos import Client, atwss
user = input('Username: ')
pswd = getpass('Password: ')
logs = input('Show detailed logs? (y/n) ').strip().lower() == 'y'
if logs:
logging.basicConfig(level=logging.DEBUG)
2022-05-18 18:35:46 +03:00
aternos = Client.from_credentials(user, pswd)
s = aternos.list_servers()[0]
socket = s.wss()
2022-06-23 14:13:56 +03:00
2022-05-18 18:35:46 +03:00
@socket.wssreceiver(atwss.Streams.console, 'Server 1')
async def console(msg, args):
print(args[0], 'received', msg)
2022-06-23 14:13:56 +03:00
2022-05-18 18:35:46 +03:00
async def main():
s.start()
await socket.connect()
await asyncio.create_task(loop())
2022-06-23 14:13:56 +03:00
2022-05-18 18:35:46 +03:00
async def loop():
while True:
await asyncio.sleep(1)
asyncio.run(main())