You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
871 B

# TODO: web frontend
import os
import tornado.web
class ExportHandler(tornado.web.RequestHandler):
def initialize(self, conn):
conn: sqlite3 connection
self.conn = conn
def get(self, range):
# TODO: userid + start time
c = self.conn.cursor()
self.set_header("Content-Type", 'text/csv')
ranges = {
'1h': '-1 hour',
'24h': '-1 day',
'week': '-7 days',
if range not in ranges:
# Not found
raise tornado.web.HTTPError(404)
c.execute("SELECT * FROM beats WHERE recordedAt > date('now', ?) ORDER BY recordedAt ASC", (ranges[range],))
for row in c:
self.write("{},{},{}\n".format(row['id'], row['bpm'], row['createdAt']))