initialer commit
This commit is contained in:
18
db.py
Normal file
18
db.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
|
||||
def log_to_db(temp=None, rain=None, wind=None, roof_state=None):
|
||||
with sqlite3.connect("data.db") as conn:
|
||||
cur=conn.cursor()
|
||||
setup = '''
|
||||
CREATE TABLE IF NOT EXISTS logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp TEXT NOT NULL,
|
||||
temp INTEGER,
|
||||
rain INTEGER,
|
||||
wind INTEGER,
|
||||
roof_open INTEGER
|
||||
)'''
|
||||
cur.execute(setup)
|
||||
query = 'INSERT INTO logs (timestamp, temp, rain, wind, roof_open) VALUES (?, ?, ?, ?, ?)'
|
||||
cur.execute(query, (datetime.now(), temp, rain, wind, roof_state))
|
||||
Reference in New Issue
Block a user