#!/usr/bin/env python # -*- coding:utf8 -*- import asyncore from ebus import EbusReader from ebus.model.sql import ModelBase, EbusSQL, Value from ebus.model.sql import EbusSQL from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker engine = create_engine('sqlite:///:memory:', echo=True) #engine = create_engine("postgresql://yvesf:iii@10.2.2.13:5432/yvesf", echo=True) ModelBase.metadata.create_all(engine) Session = sessionmaker() Session.configure(bind=engine) session = Session() class MyEbusReader(EbusReader): def __init__(self,*args,**kwargs): EbusReader.__init__(self,*args,**kwargs) self.debug = True self.sql = EbusSQL(session) def handle_ebus(self,ebus_packet): for field in self.sql.get_values(ebus_packet): session.add(field) MyEbusReader() try: asyncore.loop() except KeyboardInterrupt: for data in session.query(Value).all(): print data