18 lines
543 B
Python
18 lines
543 B
Python
import json, mcstatus
|
|
|
|
def online(server):
|
|
try:
|
|
status = server.status()
|
|
return True, status
|
|
except ConnectionRefusedError: # if it refused the connection, it's dead, Jim
|
|
return False
|
|
|
|
with open("status.json") as f:
|
|
status = json.load(f)
|
|
mc = mcstatus.MinecraftServer("mc.bhh.sh",25565)
|
|
status["online"], stats = online(mc)
|
|
status["players"] = stats.raw["players"]
|
|
if "sample" in status["players"]: status["players"]["sample"] = [x["name"] for x in status["players"]["sample"]]
|
|
with open("status.json","w") as f:
|
|
json.dump(status,f)
|