Post by encode on Dec 8, 2015 21:27:27 GMT
Hello, i drop here a simple script that give you server info plus harvest info:
import os , datetime, urllib
from xml.dom.minidom import parse
from time import sleep
_sec = 120
_urls = ["http://78.46.194.97/unlimited/stats.xml"]
_serversList = []
_harvest = [
["Olive", 85, 91],
["Oleander", 92, 112],
["Camellia", 113, 119],
["Lavender", 120, 126],
["Rose", 127, 133],
["Maple", 134, 140],
["Cherry", 169, 175],
["Olive", 197, 203],
["Grape", 225, 231],
["Apple", 245, 251],
["Walnut", 253, 259],
["Lemon", 281, 287],
["Chestnut", 323, 329]
]
_days = [
"day of the Ant",
"Luck day",
"day of the Wurm",
"Wrath day",
"day of Tears",
"day of Sleep",
"day of Awakening"
]
_weeks = [
"week 1",
"week 2",
"week 3",
"week 4"
]
_months = [
"starfall of Diamonds",
"starfall of the Saw",
"starfall of the Digging",
"starfall of the Leaf",
"Bears starfall",
"Snakes starfall",
"White Shark starfall",
"starfall of Fires",
"starfall of Reaven"
"starfall of Dancers",
"starfall of Omens",
"starfall of Silence"
]
#Clear
def _clear():
#windows
os.system('cls')
#linux
#os.system('clear')
#Sleep
def _sleep():
sleep(_sec)
#Populate
def _populate():
for index in range(0, len(_urls)):
try:
ourl = urllib.urlopen(_urls[index])
xml = parse(ourl)
lupdated = datetime.datetime.fromtimestamp(int(xml.getElementsByTagName('timestamp')[0].firstChild.nodeValue)).strftime("%B %d, %Y - %H:%M:%S")
status = xml.getElementsByTagName('status')[0].firstChild.nodeValue
m, s = divmod(int(xml.getElementsByTagName('uptime')[0].firstChild.nodeValue), 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
uptime = "%d days, %d hours and %d minutes" % (d, h, m)
wurmtime = xml.getElementsByTagName('wurmtime')[0].firstChild.nodeValue
servers = xml.getElementsByTagName('server')
name = servers[index].attributes['name'].value
players = servers[index].attributes['players'].value
maxplayers = servers[index].attributes['maxplayers'].value
days = 0
for m in range(0, len(_months)):
if _months[m] in wurmtime:
days += m*28
for w in range(0, len(_weeks)):
if _weeks[w] in wurmtime:
days += w*7
for d in range(0, len(_days)):
if _days[d] in wurmtime:
days += (d+1)
harvest = ""
for h in _harvest:
if int(h[1]) <= days <= int(h[2]):
harvest += ("[" + h[0] + "]:")
if int(h[1]-14) <= days < int(h[1]):
harvest += ("[Early " + h[0] + "]:")
if int(h[2]) < days <= int(h[2]+14):
harvest += ("[Late " + h[0] + "]:")
_serversList.append({'lupdated':lupdated,'status':status,'uptime':uptime,'wurmtime':wurmtime,'name':name,'players':players,'maxplayers':maxplayers,'days':str(days),'harvest':harvest})
except Exception as e:
print e
#Unpopulate
def _unpopulate():
global _serversList
_serversList = []
#Monitor
def _monitor():
for s in _serversList:
print "------------------------------------------------------------------------------"
print " Server: ".ljust(15) + s['name']
print " Wurm Time: ".ljust(15) + s['wurmtime']
print "------------------------------------------------------------------------------"
print " Server Time: ".ljust(15) + s['lupdated']
print " Status: ".ljust(15) + s['status']
print " Uptime: ".ljust(15) + s['uptime']
print " Players: ".ljust(15) + s['players'] + " / " + s['maxplayers']
print " Day of year: ".ljust(15) + s['days']
print " Harvest: "
for i in str(s['harvest']).rsplit(":",1)[0].split(":"):
print " -"+i
print "------------------------------------------------------------------------------"
#Init
while 1:
_populate()
_clear()
_monitor()
_unpopulate()
_sleep()