0
|
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()
|