Mercurial > code > home > repos > homeauto
diff service/rfid_pn532/graphserver.py @ 507:f3c1d2e7c5df
add missing files for the record
Ignore-this: 8541c95ef1644cf85b311259602d2892
author | drewp@bigasterisk.com |
---|---|
date | Sun, 21 Apr 2019 03:28:21 -0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/rfid_pn532/graphserver.py Sun Apr 21 03:28:21 2019 -0700 @@ -0,0 +1,34 @@ +import sys, datetime, cyclone.web, json +from twisted.internet import reactor, task +from rdflib import Namespace, Literal, ConjunctiveGraph +import rdflib_jsonld.parser +from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler + +class CurrentGraph(cyclone.web.RequestHandler): + def put(self): + g = ConjunctiveGraph() + rdflib_jsonld.parser.to_rdf(json.loads(self.request.body), g) + self.settings.masterGraph.setToGraph(g) + +def main(): + from twisted.python import log as twlog + twlog.startLogging(sys.stderr) + masterGraph = PatchableGraph() + + class Application(cyclone.web.Application): + def __init__(self): + handlers = [ + (r"/()", cyclone.web.StaticFileHandler, + {"path": ".", "default_filename": "index.html"}), + (r'/graph', CycloneGraphHandler, {'masterGraph': masterGraph}), + (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}), + (r'/currentGraph', CurrentGraph), + ] + cyclone.web.Application.__init__(self, handlers, + masterGraph=masterGraph) + + reactor.listenTCP(10012, Application()) + reactor.run() + +if __name__ == '__main__': + main()