import sysimport timeimport pymysqllights = {'bathroom light 1':0,'bathroom light 2':1,'kitchen light':2, 'bedroom light':3}conn = pymysql.connect(db='database',user='user',passwd='password',host='123.45.67.890',)cur = conn.cursor()cur.execute("SELECT * FROM lightDB WHERE user_Id = <user_id>")
Each line in cur is a tuple that has various information about the lights, the 1st (line[1]) item in the tuple is the description of the light, and the 3rd (line[3]) item is the state of whether the light is off or on.for line in cur:for key,val in lights.items():if key==line[1] and line[3]==1:print("turning",key,"on")elif key==line[1] and line[3]==0:print("turning",key,"off")
There are some obvious security concerns at this point if this database were a database maintained by the company which contained all of its users lights. For this and other reasons, we are considering restructuring our design regarding where the server for the lights is run and how the information is accessed/backed up. Look for more on this in a later post.
No comments:
Post a Comment