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.
 
 
 
 
 

27 lines
1022 B

#!/usr/bin/env python3
import sys, cgi, socket
from mcstatus import MinecraftServer
AVATAR_URI = 'https://crafatar.com/avatars/{}.png'
if len(sys.argv) < 3:
print(f'usage: {sys.argv[0]} host port', file=sys.stderr)
exit()
print('<div class="serverStatus">')
server = MinecraftServer(sys.argv[1], int(sys.argv[2]))
try:
stat = server.status()
except (ConnectionError, socket.error):
print('<div class="error">The server at {cgi.escape(sys.argv[1])}:{sys.argv[2]}appears to be down.</div>')
else:
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>')
if stat.players.online:
print('<div class="players">')
for player in stat.players.sample:
print(f'\t<div class="player"><img src="{AVATAR_URI.format(player.id)}"/><p class="name">{cgi.escape(player.name)}</p></div>')
print('</div>')
print('</div>')