This code gets hometemp and temp in one python script. twotemps.py: My test table looks like this
Code:
#!/usr/bin/python3import mysql.connectormydb = mysql.connector.connect( host="localhost", database="exampledb", user="pi", passwd="password")mycursor = mydb.cursor()sql = "select hometemp,temp from outsidetemp where id = (select max(id)-1 from outsidetemp)"mycursor.execute(sql)data = mycursor.fetchone()hometemp = data[0]temp = data[1]mycursor.close()mydb.close()print(hometemp,temp)
Code:
MariaDB [exampledb]> select * from outsidetemp;+----+----------+-------+| id | hometemp | temp |+----+----------+-------+| 1 | 21.00 | 31.20 || 2 | 22.00 | 32.20 || 3 | 23.00 | 33.20 || 4 | 24.00 | 34.20 || 5 | 25.00 | 35.20 || 6 | 26.00 | 36.20 |+----+----------+-------+
Statistics: Posted by neilgl — Sat Aug 10, 2024 12:37 pm