Teeworlds Serverlist Library for Python
Yep, made one. Too lazy to write much here. Just take a look at the example:
#!/usr/bin/env python2
from __future__ import print_function
from teeworlds import Teeworlds
# set up stuff
tw = Teeworlds(timeout=2)
# ask the masters for servers
tw.query_masters()
# query servers, wait for responses
# stops if no packet is received for `timeout` seconds
tw.run_loop()
# filter the serverlist
servers = tw.serverlist.find(
name="^C", # Server whose name begins with "C", regex style
gametype="CTF", # gametype contains "CTF"
maxping=0.1) # ping is lower or equal to 100ms
# sort by ping
servers.sort(key=lambda s: s.latency)
# display a nice list
for server in servers:
print("{server: <64} [{gametype: ^16}] on {master}: {clients: >2}/{max_clients: <2} - {latency: >4.0f} ms" \
.format(server=server.name, gametype=server.gametype, master=server.master.name, \
clients=server.clients, max_clients=server.max_clients, latency=server.latency*1000))
# check if m!nus is currently playing
minus_list = tw.playerlist.find(name="^m!nus$")
if minus_list.players:
minus = minus_list.players[0]
print("m!nus is currently playing on {server} ({address}) with {players} other player(s)."
.format(server=minus.server.name, address=minus.server.address, players=(minus.server.players-1)))
else:
print("m!nus isn't playing at the moment.")
For the zlib licensed source code click here: teeworlds.py & example