diff options
author | Ebus-at-dockstar <ebus@dockstar> | 2014-07-27 16:35:24 +0200 |
---|---|---|
committer | Ebus-at-dockstar <ebus@dockstar> | 2014-07-27 16:35:24 +0200 |
commit | db18e8146f76a0071bb7dfbde4488513c0143c4b (patch) | |
tree | 36a2f133be6c179c7250c3352ef4fd25b7105282 /heap/ebus-web-python/testfiles/bsdtest.py | |
parent | b04b3062e94c95578c4ec0436d86c9803b86b3f2 (diff) | |
download | ebus-alt-db18e8146f76a0071bb7dfbde4488513c0143c4b.tar.gz ebus-alt-db18e8146f76a0071bb7dfbde4488513c0143c4b.zip |
add ebus-alpha
Diffstat (limited to 'heap/ebus-web-python/testfiles/bsdtest.py')
-rw-r--r-- | heap/ebus-web-python/testfiles/bsdtest.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/heap/ebus-web-python/testfiles/bsdtest.py b/heap/ebus-web-python/testfiles/bsdtest.py new file mode 100644 index 0000000..b6587d0 --- /dev/null +++ b/heap/ebus-web-python/testfiles/bsdtest.py @@ -0,0 +1,49 @@ +import bsddb +import psycopg2 +from subprocess import Popen,PIPE +import time +import sys + +db = bsddb.btopen("test.btdbm") + +conn = psycopg2.connect("dbname=ebus user=ebus") +cur = conn.cursor() +sql = """SELECT * from sensor""" +cur.execute(sql) +sensors = cur.fetchall() +sensors = map(lambda a: (a[0], a[1]), sensors) +sensors = dict(sensors) +cur.close() +conn.close() + +pg_dump = Popen(["psql","-A","-t"], stdin=PIPE, stdout=PIPE) +pg_dump.stdin.write("COPY value TO stdout WITH DELIMITER '|' NULL AS '';\n") +pg_dump.stdin.close() + +c=0 +try: + while not pg_dump.stdout.closed: + line = pg_dump.stdout.readline() + c += 1 + if line == "": + continue + (oid, s_timestamp, sensor_id, type, value_float, value_int, value_string) = line.split("|") + name = sensors[int(sensor_id)] + timestamp = time.strptime(s_timestamp.split(".")[0], "%Y-%m-%d %H:%M:%S") + timestamp = time.mktime(timestamp) + if type == "int": + value= value_int + elif type == "float": + value = value_float + else: + continue + + db["%s:%d"%(name,timestamp)] = value + if c%10000==0: + print "%d: %s:%s=%s"%(c,name,s_timestamp,value) +except KeyboardInterrupt: + db.close() + +print "done" + + |