Skip to content

Instantly share code, notes, and snippets.

@richbpark
Created February 9, 2019 22:26
Show Gist options
  • Save richbpark/920af0cb0127d45ba33b3130b032c061 to your computer and use it in GitHub Desktop.
Save richbpark/920af0cb0127d45ba33b3130b032c061 to your computer and use it in GitHub Desktop.
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