blob: 9d6cf6ad043dadd32e06b43c9dca1c0e1cff1439 (
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
|
#!/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()
|