# import the libraries import tornado.web import tornado.ioloop from .ws import WebSocketHandler from .frontend import FrontendHandler from .export import ExportHandler import sqlite3 import os def start(args): basedir = os.path.dirname(os.path.realpath(__file__)) +'/../' conn = sqlite3.connect(basedir + 'heartbeat.db') conn.cursor() conn.row_factory = sqlite3.Row c = conn.cursor() c.execute(""" CREATE TABLE IF NOT EXISTS beats ( id INTEGER PRIMARY KEY AUTOINCREMENT, bpm INTEGER, beatcount INTEGER, beattime REAL, createdAt TIMESTAMP DEFAULT (datetime('now','localtime')) ); """) conn.commit() # start a new WebSocket Application # use "/" as the root, and the # WebSocketHandler as our handler application = tornado.web.Application([ (r"/", FrontendHandler, {"conn": conn}), (r"/ws", WebSocketHandler, {"conn": conn}), (r"/(.*).csv", ExportHandler, {"conn": conn}), ],debug=True) application.listen(8888) tornado.ioloop.IOLoop.instance().start()