From 6c580608f942d2f4b931faa6fe81171fd9e8a878 Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 9 Jun 2010 19:41:46 +0000 Subject: bla git-svn-id: http://10.2.2.13/svn/common/ebus@1679 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- bin/ebus_app.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 bin/ebus_app.py (limited to 'bin/ebus_app.py') 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() -- cgit v1.2.1