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 | 30 ------------------------------ bin/ebus_app.py | 38 ++++++++++++++++++++++++++++++++++++++ bin/ebus_dump | 16 ---------------- bin/ebus_dump.py | 16 ++++++++++++++++ bin/ebus_web | 10 ---------- bin/ebus_web.py | 10 ++++++++++ ebus/web/controller.py | 3 +-- 7 files changed, 65 insertions(+), 58 deletions(-) delete mode 100755 bin/ebus_app create mode 100755 bin/ebus_app.py delete mode 100644 bin/ebus_dump create mode 100644 bin/ebus_dump.py delete mode 100755 bin/ebus_web create mode 100755 bin/ebus_web.py 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 deleted file mode 100644 index 41efa33..0000000 --- a/bin/ebus_dump +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/python -# -*- coding:utf8 -*- -import asyncore -from ebus import EbusReader - -class MyEbusReader(EbusReader): - def __init__(self,*args,**kwargs): - EbusReader.__init__(self,*args,**kwargs) - self.debug=True - - def handle_ebus(self,ebus_packet): - if ebus_packet.values() != dict(): - print ebus_packet - -MyEbusReader() -asyncore.loop() diff --git a/bin/ebus_dump.py b/bin/ebus_dump.py new file mode 100644 index 0000000..bfae56e --- /dev/null +++ b/bin/ebus_dump.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding:utf8 -*- +import asyncore +from ebus import EbusReader + +class MyEbusReader(EbusReader): + def __init__(self,*args,**kwargs): + EbusReader.__init__(self,*args,**kwargs) + self.debug=True + + def handle_ebus(self,ebus_packet): + if ebus_packet.values() != dict(): + print ebus_packet + +MyEbusReader() +asyncore.loop() diff --git a/bin/ebus_web b/bin/ebus_web deleted file mode 100755 index 74fe9b9..0000000 --- a/bin/ebus_web +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -import sys -from ebus.web import controller - -from sqlalchemy import create_engine - -#db_engine = create_engine('sqlite:///:memory:', echo=True) -db_engine = create_engine("postgresql://yvesf:iii@10.2.2.13:5432/yvesf", echo=True) - -sys.exit(controller.run(db_engine)) diff --git a/bin/ebus_web.py b/bin/ebus_web.py new file mode 100755 index 0000000..74fe9b9 --- /dev/null +++ b/bin/ebus_web.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import sys +from ebus.web import controller + +from sqlalchemy import create_engine + +#db_engine = create_engine('sqlite:///:memory:', echo=True) +db_engine = create_engine("postgresql://yvesf:iii@10.2.2.13:5432/yvesf", echo=True) + +sys.exit(controller.run(db_engine)) 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.+)") def static(request,filename): file = itty.static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static')) -- cgit v1.2.1