diff options
author | yvesf <yvesf-git@xapek.org> | 2011-07-24 11:05:42 +0200 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2011-07-24 11:05:42 +0200 |
commit | 75017423563a18986aa096566d8a2969c32c3588 (patch) | |
tree | bd86ab746dd06f71ebd1b723e3bec754805e8736 /ebus/web/__init__.py | |
parent | a0382ecfbef32b47b7438170feaa7b81d7bc22db (diff) | |
download | ebus-alt-75017423563a18986aa096566d8a2969c32c3588.tar.gz ebus-alt-75017423563a18986aa096566d8a2969c32c3588.zip |
clean up file structure, use bottle soup plugin
Diffstat (limited to 'ebus/web/__init__.py')
-rw-r--r-- | ebus/web/__init__.py | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/ebus/web/__init__.py b/ebus/web/__init__.py deleted file mode 100644 index cfec3f0..0000000 --- a/ebus/web/__init__.py +++ /dev/null @@ -1,67 +0,0 @@ -# coding: utf-8 -import os -import time -import datetime -import calendar - -import bottle -from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker - -from ebus.sql import model - -app = bottle.Bottle("ebus") -bottle.debug() - -engine = create_engine("postgresql://jack:jack@10.2.2.22:5432/ebus",echo=True) -Session = sessionmaker() -Session.configure(bind=engine) - -@app.route("/") -def do_index(): - return serve_static("index.html") - -@app.route('/static/:filename') -def serve_static(filename): - return bottle.static_file(filename, - root=os.path.join(os.path.dirname(__file__),"static")) - -@app.route("/list") -def list(): - sensors = Session().query(model.Sensor).all() - return {"type":"list","data":map(lambda sensor: sensor.name, sensors)} - -@app.route("/:when#today|yesterday|week|month#/:sensor") -def get_value(when,sensor): - s = Session() - sensor = s.query(model.Sensor).filter(model.Sensor.name == sensor).first() - values = Session().query(model.Value).add_columns("value_float","value_string","value_int") - values = values.filter(model.Value.sensor == sensor) - - now = datetime.datetime.now() - f,t = None, None - if when == "today": - f = now.date() - t = now.date() + datetime.timedelta(1) - elif when == "yesterday": - f = now.date() - datetime.timedelta(1) - t = now - elif when == "week": - f = now.date() - datetime.timedelta(now.isoweekday()) - t = now.date() + datetime.timedelta(7-now.isoweekday()) - elif when == "month": - f = now.date() - datetime.timedelta(now.day) - t = f + datetime.timedelta( calendar.monthrange(f.year, f.month)[1] ) - else: - raise Exception("illegal timerange") - - values = values.filter(model.Value.timestamp.between(f,t)) - x = values.all() - - v=[] - for value in values.all(): - v.append(value.value()) - return {"type":when,"data":v} - - - |