Mercurial > code > home > repos > homeauto
comparison service/environment/environment.py @ 0:6fd208b97616
start
Ignore-this: e06ac598970a0d4750f588ab89f56996
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Mon, 01 Aug 2011 03:30:30 -0700 |
parents | |
children | 5c9927555df6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6fd208b97616 |
---|---|
1 #!/usr/bin/python | |
2 """ | |
3 return some rdf about the environment, e.g. the current time, | |
4 daytime/night, overall modes like 'maintenance mode', etc | |
5 | |
6 """ | |
7 import sys, datetime, cyclone.web | |
8 from twisted.internet import reactor | |
9 from dateutil.tz import tzlocal | |
10 from rdflib import Namespace, Literal | |
11 sys.path.append("/my/site/magma") | |
12 from stategraph import StateGraph | |
13 sys.path.append("/my/proj/homeauto/lib") | |
14 from cycloneerr import PrettyErrorHandler | |
15 | |
16 ROOM = Namespace("http://projects.bigasterisk.com/room/") | |
17 DEV = Namespace("http://projects.bigasterisk.com/device/") | |
18 | |
19 class Index(PrettyErrorHandler, cyclone.web.RequestHandler): | |
20 def get(self): | |
21 self.write('this is envgraph: <a href="graph">rdf</a>') | |
22 | |
23 class GraphHandler(PrettyErrorHandler, cyclone.web.RequestHandler): | |
24 def get(self): | |
25 g = StateGraph(ROOM.environment) | |
26 now = datetime.datetime.now(tzlocal()) | |
27 | |
28 g.add((DEV.environment, ROOM.localHour, Literal(now.hour))) | |
29 | |
30 self.set_header('Content-type', 'application/x-trig') | |
31 self.write(g.asTrig()) | |
32 | |
33 class Application(cyclone.web.Application): | |
34 def __init__(self): | |
35 handlers = [ | |
36 (r"/", Index), | |
37 (r'/graph', GraphHandler), | |
38 ] | |
39 cyclone.web.Application.__init__(self, handlers) | |
40 | |
41 if __name__ == '__main__': | |
42 reactor.listenTCP(9075, Application()) | |
43 reactor.run() |