Here's the Python code used to take the output file from the sensors and calculate the average value over the time period and then output a text level (low, med etc) depending on the values enters as argument whent he script is run.
The script is run from a cronjob using something like "/mnt/sda1/average.py /mnt/sda1/ozone.txt /mnt/sda1/ozoneresult.txt 900 1050 1200"
The arguments relate to the low, medium, high levels output.
This is then followed in the cronjob by the script to send a tweet which uses the output from this (ozoneresult.txt) to choose the text for the tweet.
Here's the code:
fileinput = sys.argv
fileoutput = sys.argv
#get level values
low = int(sys.argv)
medium = int(sys.argv)
high = int(sys.argv)
list_of_numbers = 
with open(fileinput) as f:
for line in f:
if line.strip(): # this skips blank lines
#print 'Total ',len(list_of_numbers)
#print 'Average ',1.0*sum(list_of_numbers)/len(list_of_numbers)
f = open(fileoutput, "w") #reopen file to clear it
#change 1 below to 1.0 to get float result instead of integer
f.write(average + " (" + leveltxt + ")") #write the average calculated from the orig$