blob: 2d6933cd596628f9f641a69ca2717215359b9cc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/env python
# -*- coding:utf8 -*-
import asyncore
import time
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
import logging
logging.basicConfig()
#logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNING)
logger = logging.getLogger('ebus.dump')
logger.setLevel(logging.INFO)
#engine = create_engine('sqlite:///:memory:', echo=True)
engine = create_engine("postgresql:///ebus")
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)
if int(time.time()) % 4 == 0:
logger.info("COMMIT")
session.commit()
logger.info("packet %s" % ebus_packet.name())
MyEbusReader()
try:
asyncore.loop()
except KeyboardInterrupt:
pass
# for data in session.query(Value).all():
# print data
|