From 75017423563a18986aa096566d8a2969c32c3588 Mon Sep 17 00:00:00 2001 From: yvesf Date: Sun, 24 Jul 2011 11:05:42 +0200 Subject: clean up file structure, use bottle soup plugin --- ebus/webapp/__init__.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'ebus/webapp/__init__.py') 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)) -- cgit v1.2.1