Skip to content

Instantly share code, notes, and snippets.

@richbpark richbpark/myDBquery.py Secret
Created Feb 9, 2019

Embed
What would you like to do?
myDBquery.py queries lab_app.db sqlite3 DB for 20 most recent temp/hum values.
#######################################################
# myDBquery.py #
# Rich Park February 09, 2019 #
# A program to query the temperature and humidities #
# from the RPiFSv2 Database #
#######################################################
import sqlite3
import os # Allow for calls to the shell
os.system('clear') # This call clears the screen. Very helpful for avoiding testing clutter.
conn=sqlite3.connect('/var/www/lab_app/lab_app.db')
curs=conn.cursor()
curs.execute("SELECT * FROM temperatures")
temperatures = curs.fetchall()
curs.execute("SELECT * FROM humidities")
humidities = curs.fetchall()
conn.close()
# Get the 20 most recent temperature and humidity readings
for item in range ((len(temperatures) - 20), len(temperatures)):
# Do a bit of formatting to make the output more readable.
# NOTE: the u"\u2103" entry displays the 'degrees centigrade symbol.
print (item," Temperature -> ", str(("{:.2f}".format)(temperatures \
[item] [2])),u"\u2103"," ", (temperatures[item][0]), sep='')
print (" Humidity ", str(("{:.2f}".format)(humidities \
[item] [2])),"%", sep='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.