Skip to content

Instantly share code, notes, and snippets.

@adamgreig
Created July 17, 2010 16:31
Show Gist options
  • Save adamgreig/479627 to your computer and use it in GitHub Desktop.
Save adamgreig/479627 to your computer and use it in GitHub Desktop.
import cherrypy
from pygooglechart import GoogleOMeterChart
import urllib, urllib2
def getdata():
page = urllib2.urlopen("http://robertharrison.org/listen/view.php?reg=/APEX/")
lastdata = []
lines = page.read().split("\n")
for line in lines:
data = "".join(line.split(" : ")[1:]).split(",")
print data
if data[0] == "APEX" and (len(data) == 17 or len(data) == 18):
lastdata = data
print data
else:
continue
data = lastdata
if not (len(data) == 17 or len(data) == 18):
return {}
int_temp = float(data[9])
ext_temp = float(data[10])
pressure = (float(int(data[11], 16)) * 0.2713336047) + 105.5555556
battery = float(int(data[12], 16)) * 0.00244
ird1 = int(data[13], 16)
ird2 = int(data[14], 16)
light = int(data[15], 16)
rssi = int(data[16].split("*")[0], 16)
return {
'it': int_temp,
'et': ext_temp,
'p': pressure,
'b': battery,
'i1': ird1,
'i2': ird2,
'l': light,
'r': rssi
}
def chart(xrng, title, data, colours, label):
c = GoogleOMeterChart(256, 128, x_range=xrng)
c.set_title(title)
c.add_data([data])
c.set_colours(colours)
c.set_pie_labels([label])
return c.get_url()
class Root:
def index(self):
return "hello, world!"
index.exposed = True
class Apex2:
def index(self):
data = getdata()
if len(data) == 0:
return "no data"
url1 = chart([-50,30], "internal temp", data['it'], ["0000FF", "FF0000"], str(data['it'])+"C")
url2 = chart([-50,30], "external temp", data['et'], ["0000FF", "FF0000"], str(data['et'])+"C")
url3 = chart([0,1100], "pressure", data['p'], ["FF0000", "00FF00"], str(round(data['p'], 2))+"mbar")
url4 = chart([5,7], "battery", data['b'], ["FF0000", "00FF00"], str(data['b'])+"V")
url5 = chart([0,500], "rad1 (counts/20s)", data['i1'], ["00FF00", "FF0000"], str(data['i1']))
url6 = chart([0,500], "rad2 (counts/20s)", data['i2'], ["00FF00", "FF0000"], str(data['i2']))
url7 = chart([0,255], "rssi", data['r'], ["FF0000", "00FF00"], str(data['r'])+"/255")
return '<html><head><title>apex 2</title></head><body><img src="%s" /><img src="%s" /><img src="%s" /><img src="%s" /><img src="%s" /><img src="%s" /><img src="%s" /></body></html>' % (url1, url2, url3, url4, url5, url6, url7)
index.exposed = True
root = Root()
root.apex2 = Apex2()
app = cherrypy.tree.mount(root, script_name='/')
cherrypy.quickstart(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment