#!/usr/bin/python2 import urllib2 import xml.etree.ElementTree as ET import socket from MythTV import Frontend import sys #socket.setdefaulttimeout(1) #socket.setdefaulttimeout(.00001) def msg(msg): #if cmdargs.silent is False: print "%s" %msg def parse_xml(frontend): temp_dict = {'state':" --- ", 'title':" --- ", 'subtitle':" --- ", 'location':" --- "} url = "http://%s:6547/Frontend/GetStatus" %frontend try: request = urllib2.Request(url) xml = urllib2.urlopen(request,timeout=1) tree = ET.parse(xml) root = tree.getroot() except: #msg(" Couldn't connect to %s" %frontend) temp_dict['state'] = "offline" return temp_dict lst = root.find("State") for item in lst: try: keyitem = (item.find('Key').text).strip() valueitem = (item.find('Value').text).strip() except: continue if keyitem == "state": temp_dict['state'] = valueitem elif keyitem == "title": temp_dict['title'] = valueitem elif keyitem == "subtitle": temp_dict['subtitle'] = valueitem elif keyitem == "currentlocation": temp_dict['location'] = valueitem return temp_dict def mythfe_status(cursor,mythDB): status_dict={} try: #frontends = mythDB.getFrontends() #use cursor instead so it doesn't test connection cursor.execute("select distinct hostname from settings where hostname is not null;") frontends=cursor.fetchall() except: #msg("Exceptions") return for i in frontends: i=''.join(i) try: fe_hostname = socket.gethostbyaddr(i)[0] except: #print "DNS lookup failed for %s" %i fe_hostname = i try: ip_addr = socket.gethostbyname(i) fe_hostname = "%s (%s)" %(fe_hostname,ip_addr) status_dict[fe_hostname] = parse_xml(ip_addr) except: fe_hostname = "%s" %fe_hostname status_dict[fe_hostname] = parse_xml(fe_hostname) return status_dict def print_html(status_dict): print '
%s | %s | %s | %s | %s |