diff options
Diffstat (limited to 'ebus/webapp/__init__.py')
-rw-r--r-- | ebus/webapp/__init__.py | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/ebus/webapp/__init__.py b/ebus/webapp/__init__.py index 2a92b57..9870e95 100644 --- a/ebus/webapp/__init__.py +++ b/ebus/webapp/__init__.py @@ -1,39 +1,25 @@ # -*- coding: utf-8 -*- # vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python - -import bottle -import sqlalchemy -from sqlalchemy import create_engine, select -from sqlalchemy.orm import sessionmaker -from sqlalchemy.sql import text - -from sqlalchemy.ext.sqlsoup import SqlSoup -from sqlalchemy import or_, and_, desc - -from ebus.sql import model import os import json import datetime import time -app = bottle.Bottle("ebus") -bottle.debug() -engine = create_engine("postgresql:///ebus", echo=True) -Session = sessionmaker() -Session.configure(bind=engine) +import bottle +from sqlalchemy import text -soup = SqlSoup(engine) +app = bottle.Bottle("ebus") @app.route('/') def index_file(): return static_files("index.html") -@app.route('/static/:filename') +@app.route('/static/:filename#.+#') def static_files(filename): return bottle.static_file(filename, root=os.path.join(os.path.dirname(__file__),"static")) @app.route('/sensor/:name') -def sensor_data(name): +def sensor_data(soup,name): try: # get sensor_id for name sensor_id = soup.sensor.filter(soup.sensor.name == name).one().id @@ -52,7 +38,7 @@ def sensor_data(name): return {'sensor':name,'data':None, 'error':str(e)} @app.route('/sensor/:name/:startdate/:enddate') -def sensor_data_fromto(name,startdate,enddate): +def sensor_data_fromto(soup,name,startdate,enddate): try: interval = float(enddate) - float(startdate) if interval <= 0: raise Exception("Invalid interval") @@ -94,7 +80,7 @@ def maketime(datetime): return (time.mktime(datetime.timetuple())+time.altzone*-1)*1000 @app.route('/sensor_cached/:name/:timestamp_from') -def sensor_data_cached_fromto(name, timestamp_from): +def sensor_data_cached_fromto(soup, name, timestamp_from): try: timestamp_from = datetime.datetime.fromtimestamp(float(timestamp_from)) |