Compare commits

..

1 Commits

Author SHA1 Message Date
0xee 6c14800a02 Add mqtt-collect script 2020-03-30 20:23:14 +02:00
1 changed files with 8 additions and 2 deletions

View File

@ -10,6 +10,14 @@ import datetime
def init_db(path, topics):
db = sqlite3.connect(path)
c = db.cursor()
for topic in topics:
table = topic.replace('/', '_')
c.execute(
f'CREATE TABLE IF NOT EXISTS {table} (timestamp timestamp, value real)'
)
db.commit()
return db
@ -37,8 +45,6 @@ def main():
table = msg.topic.replace("/", "_")
ts = datetime.datetime.now()
value = float(msg.payload)
c.execute(f'CREATE TABLE IF NOT EXISTS {table} '
'(timestamp timestamp, value real)')
c.execute(f'INSERT INTO {table} VALUES (?, ?)', (ts, value))
c.execute(f'SELECT * from {table}')
db.commit()