Skip to content
Permalink
Browse files

[Server] Use official server list instead of servers.minetest.ru

  • Loading branch information
sfan5 committed Apr 25, 2013
1 parent 3249e14 commit b3f839398f1ef69accd0d23bfa4e32bcd4c91500
Showing with 13 additions and 25 deletions.
  1. +13 −25 server.py
@@ -4,34 +4,22 @@
Copyright 2012, Sfan5
"""

import web, math, random
from xml.dom import minidom
import web, json, random

def read_server():
bytes = web.get("http://servers.minetest.ru/")
shim = '<table>'
shim2 = '</table>'
if shim in bytes and shim2 in bytes:
bytes = bytes.split(shim, 1).pop()
bytes = bytes.split(shim2, 1)[0]
bytes = "<table>" + bytes + "</table>" # Root Tag needed
dom = minidom.parseString(bytes)
l = dom.getElementsByTagName("tr")
chosen = l[int(math.floor(random.random()*(len(l)-1))+1)]
datas = chosen.getElementsByTagName("td")
name = datas[0].firstChild.data # Server Name
addr = datas[1].firstChild.data # Server Address
status = datas[3].firstChild.data # Status (up/down)
statuspercent = datas[4].firstChild.firstChild.data # Status Percent
return format(name,addr,status,statuspercent)
return "Unknown Error"

text = web.get("http://servers.minetest.net/list")
server_list = json.loads(text)["list"]
choice = random.randrange(0, len(server_list))

name = server_list[choice]["name"]
address = server_list[choice]["address"]
clients = server_list[choice]["clients"]
version = server_list[choice]["version"]
ping = server_list[choice]["ping"]
clients_top = server_list[choice]["clients_top"]

return "%s | %s | Clients: %s/%s | Version: %s | ping: %s" % (name, address, clients, clients_top, version, ping)

def format(name,addr,status,statuspercent):
if status == "up":
return "%s | %s %s (%s)" % (name,addr,status,statuspercent)
else:
return "%s | %s %s" % (name,addr,status)
def server(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":

0 comments on commit b3f8393

Please sign in to comment.