initialer commit

This commit is contained in:
2025-06-09 13:18:00 +02:00
commit 0f8507284f
7 changed files with 158 additions and 0 deletions

18
db.py Normal file
View 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))