Teaching myself Python Day 3

in ulog •  6 months ago 

I made several changes today. I noticed that the Max temperature query was looking at all of the temperatures in the database not just a single sensor. So I changed the query to just query the RearDeck sensor. I also changed the query to automatically get today's date and not hardcode the date.


import datetime
import time
import MySQLdb
from tkinter import *
from tkinter.ttk import *

window =Tk()
window.title("Pylearn Day 4")
lbl = Label(window, text="day 4", font=("Arial Bold", 50))

querydate = str(datetime.date.today())

def clicked2():
    db = MySQLdb.connect("", "pidata", "Rasp!data99", "home_data")
    cursor = db.cursor()
    sqlcmd = "select max(temp) from temperatures where tempTime like '" + querydate + "%' and location like 'RearDeck';"
    row = cursor.fetchone()
    lbl.configure(text= querydate + "  Max Temp " + str(row[0]), font=("Arial Bold", 24))

button_2 = Button(window, text="Click for max temp", command=clicked2)


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Good catch on the sql query.