diff service/environment/environment.py @ 805:9e99114dde57

start Ignore-this: e06ac598970a0d4750f588ab89f56996 darcs-hash:20110801103030-836b1-376453383c1b9c6daac50cc790aa98906846fe56.gz
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 01 Aug 2011 03:30:30 -0700
parents
children 5c9927555df6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/environment/environment.py	Mon Aug 01 03:30:30 2011 -0700
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+"""
+return some rdf about the environment, e.g. the current time,
+daytime/night, overall modes like 'maintenance mode', etc
+
+"""
+import sys, datetime, cyclone.web
+from twisted.internet import reactor
+from dateutil.tz import tzlocal
+from rdflib import Namespace, Literal
+sys.path.append("/my/site/magma")
+from stategraph import StateGraph
+sys.path.append("/my/proj/homeauto/lib")
+from cycloneerr import PrettyErrorHandler
+
+ROOM = Namespace("http://projects.bigasterisk.com/room/")
+DEV = Namespace("http://projects.bigasterisk.com/device/")
+
+class Index(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def get(self):
+        self.write('this is envgraph: <a href="graph">rdf</a>')
+        
+class GraphHandler(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def get(self):
+        g = StateGraph(ROOM.environment)
+        now = datetime.datetime.now(tzlocal())
+
+        g.add((DEV.environment, ROOM.localHour, Literal(now.hour)))
+        
+        self.set_header('Content-type', 'application/x-trig')
+        self.write(g.asTrig())
+        
+class Application(cyclone.web.Application):
+    def __init__(self):
+        handlers = [
+            (r"/", Index),
+            (r'/graph', GraphHandler),
+        ]
+        cyclone.web.Application.__init__(self, handlers)
+
+if __name__ == '__main__':
+    reactor.listenTCP(9075, Application())
+    reactor.run()