nilmdb/pytables-test/server.py

54 lines
1009 B
Python
Raw Permalink Normal View History

import sys
import tables
import nilmdb
try:
import cherrypy
cherrypy.tools.json_out
except:
sys.stderr.write("Cherrypy 3.2+ required\n")
sys.exit(1)
class NilmApp:
def __init__(self, db):
self.db = db
class Root(NilmApp):
"""NILM Database"""
server_version = "1.0"
@cherrypy.expose
def index(self):
raise cherrypy.NotFound()
@cherrypy.expose
def favicon_ico(self):
raise cherrypy.NotFound()
@cherrypy.expose
@cherrypy.tools.json_out()
def version(self):
return self.server_version
class Stream(NilmApp):
"""Stream operations"""
@cherrypy.expose
@cherrypy.tools.json_out()
def list(self):
return
cherrypy.config.update({
'server.socket_host': '127.0.0.1',
'server.socket_port': 12380
})
db = nilmdb.nilmdb()
cherrypy.tree.mount(Root(db), "/")
cherrypy.tree.mount(Stream(db), "/stream")
if __name__ == "__main__":
cherrypy.engine.start()
cherrypy.engine.block()