-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadlast.py
More file actions
28 lines (22 loc) · 794 Bytes
/
readlast.py
File metadata and controls
28 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sqlite3
#import time
import datetime
#import random
#import dateutil
import matplotlib.pyplot as plt
conn = sqlite3.connect('/home/ddskrjo/tempsensor/esp32-tempsensor/temperatures.db')
c = conn.cursor()
def read_from_db():
sensor1str = "vallen%"
sensor2str = "cirkel%"
oneweekago = datetime.datetime.now()- datetime.timedelta(days=7)
weekStr = oneweekago.strftime("%Y-%m-%d")
print(weekStr)
c.execute('SELECT sensor_id, temperature, timestamp FROM readings where timestamp > \'' +
weekStr + '\' and (sensor_id like \'' +
sensor1str + '\' or sensor_id LIKE \'' + sensor2str + '\') order by timestamp desc')
#c.execute('SELECT * FROM readings')
data = c.fetchall()
for i in range(0,10):
print(f"{i}:{data[9-i]}")
read_from_db()