Mercurial > code > home > repos > homeauto
changeset 60:3c40d92b2db3
wallscreen switch to html5 and cyclone. add temporary temperature poller
Ignore-this: 2606b551325933d2a42b14292605b967
author | drewp@bigasterisk.com |
---|---|
date | Sun, 10 Feb 2013 12:06:17 -0800 |
parents | 7ec777c93d51 |
children | 1afb0564636d |
files | service/wallscreen/index.html service/wallscreen/pydeps service/wallscreen/wallscreen.py |
diffstat | 3 files changed, 92 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/service/wallscreen/index.html Sun Feb 10 02:27:03 2013 -0800 +++ b/service/wallscreen/index.html Sun Feb 10 12:06:17 2013 -0800 @@ -1,10 +1,8 @@ -<?xml version="1.0" encoding="iso-8859-1"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" -"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> +<!DOCTYPE html> +<html> <head> <title>wallscreen</title> - <link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400' rel='stylesheet' type='text/css'> + <link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400' rel='stylesheet' type='text/css'></link> <style type="text/css" media="all"> /* <![CDATA[ */ body { @@ -42,7 +40,6 @@ } #clock { - bottom: 25px; color: #4E8B4E; font-size: 56px; @@ -51,8 +48,6 @@ right: 5px; text-align: right; width: 134px; - - } #todo { @@ -121,7 +116,7 @@ #thermostat { position: absolute; left: 8px; -top: 650px; +top: 640px; } /* ]]> */ @@ -161,7 +156,7 @@ </ul> </div> <div id="thermostat"> - Thermostat at <span data-bind="text: requestedF"></span>. Use knob to adjust + Thermostat at <span style="color: #FAB1FA;" data-bind="text: requestedF"></span>. Use knob to adjust. </div> </div> @@ -198,7 +193,7 @@ $.getJSON("/thermostat", function (data) { model.requestedF(data.tempF); }); -}, 3000); +}, 1000); ko.applyBindings(model);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/wallscreen/pydeps Sun Feb 10 12:06:17 2013 -0800 @@ -0,0 +1,11 @@ +Twisted==12.3.0 +cyclone==1.0-rc15 +distribute==0.6.24 +ipdb==0.7 +ipython==0.13.1 +isodate==0.4.9 +pyOpenSSL==0.13 +python-dateutil==2.1 +rdflib==3.2.3 +six==1.2.0 +zope.interface==4.0.3
--- a/service/wallscreen/wallscreen.py Sun Feb 10 02:27:03 2013 -0800 +++ b/service/wallscreen/wallscreen.py Sun Feb 10 12:06:17 2013 -0800 @@ -4,78 +4,91 @@ and then fix the window with this: echo "window.resizeTo(702,480)" | nc localhost 9999 """ -import bottle, json, pystache, restkit +import json, sys from dateutil.parser import parse +from twisted.internet import reactor +from twisted.internet.defer import inlineCallbacks +import cyclone.web, cyclone.httpclient, cyclone.websocket from rdflib import Graph, URIRef, Namespace, Literal, RDF + +sys.path.append("../../lib") +from logsetup import log +from cycloneerr import PrettyErrorHandler + CV = Namespace("http://bigasterisk.com/checkvist/v1#") EV = Namespace("http://bigasterisk.com/event#") -@bottle.route('/') -def index(): - return pystache.render(open("vist.html").read()) +class Content(PrettyErrorHandler, cyclone.web.RequestHandler): + def get(self): + out = [] + if 0: # needs to be rewritten for trello + g = Graph() + g.parse("http://bang:9103/graph", format="n3") -@bottle.route("/content") -def content(): - - out = [] - if 0: # needs to be rewritten for trello - g = Graph() - g.parse("http://bang:9103/graph", format="n3") + tasks = [] # (pos, task) + for t in g.subjects(RDF.type, CV.OpenTask): + if (None, CV.child, t) in g: + continue + tasks.append((g.value(t, CV.position), t)) + tasks.sort() - tasks = [] # (pos, task) - for t in g.subjects(RDF.type, CV.OpenTask): - if (None, CV.child, t) in g: - continue - tasks.append((g.value(t, CV.position), t)) - tasks.sort() + def appendTree(t, depth): + out.append(dict( + uri=t, + depth=depth, + mark=g.value(t, CV.mark), + content=g.value(t, CV.content), + )) + for sub in g.objects(t, CV.child): + if (sub, RDF.type, CV.OpenTask) not in g: + continue + appendTree(sub, depth+1) - def appendTree(t, depth): - out.append(dict( - uri=t, - depth=depth, - mark=g.value(t, CV.mark), - content=g.value(t, CV.content), - )) - for sub in g.objects(t, CV.child): - if (sub, RDF.type, CV.OpenTask) not in g: - continue - appendTree(sub, depth+1) + for pos, t in tasks[:10]: + appendTree(t, depth=0) - for pos, t in tasks[:10]: - appendTree(t, depth=0) + events = [] # [{'date':'yyyy-mm-dd', 'dayEvents':[], 'timeEvents':[]}] + g = Graph() + g.parse("http://bang:9105/events?days=3", format='n3') + byDay = {} + for ev in g.subjects(RDF.type, EV.Event): + start = g.value(ev, EV['start']) + s = parse(start) + d = s.date().isoformat() + byDay.setdefault(d, {'dayEvents':[], + 'timeEvents':[]})[ + 'timeEvents' if 'T' in start else 'dayEvents'].append({ + 'title' : g.value(ev, EV['title']), + 'start' : start, + 'date' : s.date().isoformat(), + 'time' : s.time().isoformat()[:-3], + }) + for k,v in sorted(byDay.items(), key=lambda (k,v): k): + d = {'date':k, 'weekdayName':parse(k).strftime("%A")} + d.update(v) + d['dayEvents'].sort(key=lambda ev: ev['title']) + d['timeEvents'].sort(key=lambda ev: ev['start']) + events.append(d) - events = [] # [{'date':'yyyy-mm-dd', 'dayEvents':[], 'timeEvents':[]}] - g = Graph() - g.parse("http://bang:9105/events?days=3", format='n3') - byDay = {} - for ev in g.subjects(RDF.type, EV.Event): - start = g.value(ev, EV['start']) - s = parse(start) - d = s.date().isoformat() - byDay.setdefault(d, {'dayEvents':[], - 'timeEvents':[]})[ - 'timeEvents' if 'T' in start else 'dayEvents'].append({ - 'title' : g.value(ev, EV['title']), - 'start' : start, - 'date' : s.date().isoformat(), - 'time' : s.time().isoformat()[:-3], - }) - for k,v in sorted(byDay.items(), key=lambda (k,v): k): - d = {'date':k, 'weekdayName':parse(k).strftime("%A")} - d.update(v) - d['dayEvents'].sort(key=lambda ev: ev['title']) - d['timeEvents'].sort(key=lambda ev: ev['start']) - events.append(d) - - return {'tasks':out, 'events' : events} + self.write(json.dumps({'tasks':out, 'events' : events})) -@bottle.route("/thermostat") -def thermostat(): - return restkit.request("http://bang:10001/requestedTemperature").body_string() +class Thermostat(PrettyErrorHandler, cyclone.web.RequestHandler): + @inlineCallbacks + def get(self): + self.write((yield cyclone.httpclient.fetch("http://bang:10001/requestedTemperature")).body) -@bottle.route('/static/<path:path>') -def server_static(path): - return bottle.static_file(path, root='static') - -bottle.run(host="0.0.0.0", port=9102) +if __name__ == '__main__': + from twisted.python import log as twlog + #twlog.startLogging(sys.stdout) + + port = 9102 + reactor.listenTCP(port, cyclone.web.Application(handlers=[ + (r'/content', Content), + (r'/thermostat', Thermostat), + (r'/(.*)', cyclone.web.StaticFileHandler, + {"path" : ".", # security hole- serves this dir too + "default_filename" : "index.html"}), + ])) + log.info("serving on %s" % port) + reactor.run()