diff options
-rwxr-xr-x | bin/ebus_app | 30 | ||||
-rwxr-xr-x | bin/ebus_app.py | 38 | ||||
-rw-r--r-- | bin/ebus_dump.py (renamed from bin/ebus_dump) | 2 | ||||
-rwxr-xr-x | bin/ebus_web.py (renamed from bin/ebus_web) | 0 | ||||
-rw-r--r-- | ebus/web/controller.py | 3 |
5 files changed, 40 insertions, 33 deletions
diff --git a/bin/ebus_app b/bin/ebus_app deleted file mode 100755 index d381254..0000000 --- a/bin/ebus_app +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf8 -*- -# xapek.org, 2010 -import asyncore -from pymongo import Connection -from ebus import EbusReader -from time import time - -connection = Connection("10.2.2.13", 27017) -db = connection["ebus"] -db.authenticate("ebus", "ebus") -collection = db["data"] - -def insert(ebus_packet): - try: - if ebus_packet.values() != dict(): - data={'name':ebus_packet.name(), 'values':ebus_packet.values(), 'time':time()} - collection.insert(data) - print "Inserted: %s" % data - except Exception,e: - try: - print "Failed to insert %s -- %s" % (ebus_packet.name(), e) - except Exception,e: - print e - -reader = EbusReader() -reader.handle_ebus = insert -reader.debug = False - -asyncore.loop() diff --git a/bin/ebus_app.py b/bin/ebus_app.py new file mode 100755 index 0000000..9d6cf6a --- /dev/null +++ b/bin/ebus_app.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# xapek.org, 2010 +import asyncore +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from ebus.web import model +from ebus import EbusReader + +#db_engine = create_engine('sqlite:///:memory:', echo=True) +db_engine = create_engine("postgresql://yvesf:iii@10.2.2.13:5432/yvesf", echo=True) + +session = sessionmaker(bind=db_engine)() + + +def insert(ebus_packet): + try: + if len(ebus_packet.values()) > 0: + for name,value in ebus_packet.values(): + sensor = session.query().filter(name=name).first() + if not sensor: + sensor = model.Sensor(name) + session.add(sensor) + m_value = model.Value(sensor, value) + session.add(m_value) + print m_value + session.commit() + except Exception,e: + try: + print "Failed to insert %s -- reason %s" % (ebus_packet.name(), e) + except Exception,e: + print e + +reader = EbusReader() +reader.handle_ebus = insert +reader.debug = False + +asyncore.loop() diff --git a/bin/ebus_dump b/bin/ebus_dump.py index 41efa33..bfae56e 100644 --- a/bin/ebus_dump +++ b/bin/ebus_dump.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding:utf8 -*- import asyncore from ebus import EbusReader diff --git a/bin/ebus_web b/bin/ebus_web.py index 74fe9b9..74fe9b9 100755 --- a/bin/ebus_web +++ b/bin/ebus_web.py diff --git a/ebus/web/controller.py b/ebus/web/controller.py index 406db01..f581e13 100644 --- a/ebus/web/controller.py +++ b/ebus/web/controller.py @@ -48,11 +48,10 @@ def index(req): @CacheDecorator(key=lambda args,kwargs: tuple(kwargs.keys()) + tuple(kwargs.values()), timeout=20) def json(req,sensor=None,from_date=None,till_date=None): - print "name=%s from_date=%s" % (name,from_date) + print "sensor=%s from_date=%s till_date=%s" % (sensor,from_date,till_date) return itty.Response(dump_json(data(sensor)), content_type="application/json") - @itty.get("/static/(?P<filename>.+)") def static(request,filename): file = itty.static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static')) |