Hello. The situation is as follows...
I use rrdtool to plot the outside and inside temperature graphs, the data of which is kept in a mysql database.
rrdtool update file is this:outtemp.py file is this: hometemp.py file is this: My question is how can I optimize the speed and the code to use with one python file (one connection to mysql - not two) for the two values (data1 & data2) and to use them with rddtool update file?
I`ll need help for python code and bash code as well
Thanks
I use rrdtool to plot the outside and inside temperature graphs, the data of which is kept in a mysql database.
rrdtool update file is this:
Code:
#!/bin/bashcd /home/w1/year/rrdtool=/usr/bin/rrdtooldata1=$(python3 /home/w1/year/outtemp.py)data2=$(python3 /home/w1/year/hometemp.py)$rrdtool update year.rrd --template out:home N:$data1:$data2
Code:
#!/usr/bin/python3import mysql.connectormydb = mysql.connector.connect( host="192.168.0.101", database="********", user="w1", passwd="********")mycursor = mydb.cursor()sql = "select temp from outsidetemp where id = (select max(id)-1 from outsidetemp)"mycursor.execute(sql)data = mycursor.fetchone()last = (data[0])mydb.commit()mycursor.close()mydb.close()print(last)
Code:
#!/usr/bin/python3import mysql.connectormydb = mysql.connector.connect( host="192.168.0.101", database="********", user="w1", passwd="********")mycursor = mydb.cursor()sql = "select hometemp from outsidetemp where id = (select max(id)-1 from outsidetemp)"mycursor.execute(sql)data = mycursor.fetchone()last = (data[0])mydb.commit()mycursor.close()mydb.close()print(last)
I`ll need help for python code and bash code as well

Statistics: Posted by independent — Sat Aug 10, 2024 9:17 am