19 lines
653 B
Python
19 lines
653 B
Python
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))
|