website for lusty lavender: http://eln.ja13.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.py 1022B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python3
  2. import sys, cgi, socket
  3. from mcstatus import MinecraftServer
  4. AVATAR_URI = 'https://crafatar.com/avatars/{}.png'
  5. if len(sys.argv) < 3:
  6. print(f'usage: {sys.argv[0]} host port', file=sys.stderr)
  7. exit()
  8. print('<div class="serverStatus">')
  9. server = MinecraftServer(sys.argv[1], int(sys.argv[2]))
  10. try:
  11. stat = server.status()
  12. except (ConnectionError, socket.error):
  13. print('<div class="error">The server at {cgi.escape(sys.argv[1])}:{sys.argv[2]}appears to be down.</div>')
  14. else:
  15. print(f'<div class="statusLine"><span class="serverName">{cgi.escape(stat.description)}</span> is up: <span class="online">{stat.players.online}</span>/<span class="max">{stat.players.max}</span> players</div>')
  16. if stat.players.online:
  17. print('<div class="players">')
  18. for player in stat.players.sample:
  19. print(f'\t<div class="player"><img src="{AVATAR_URI.format(player.id)}"/><p class="name">{cgi.escape(player.name)}</p></div>')
  20. print('</div>')
  21. print('</div>')