Air Quality - calculate average and assign a text level value

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:

#!/usr/bin/python
import sys
fileinput = sys.argv[1]
fileoutput = sys.argv[2]
#get level values
low = int(sys.argv[3])
medium = int(sys.argv[4])
high = int(sys.argv[5])

list_of_numbers = []

with open(fileinput) as f:
for line in f:
if line.strip(): # this skips blank lines
list_of_numbers.append(float(line.strip()))

#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
averageint=int(1*sum(list_of_numbers)/len(list_of_numbers))
average=str(averageint)

if averageint leveltxt="low"
elif averageint leveltxt="low-med"
elif averageint leveltxt="medium"
else:
leveltxt="high"

f.write(average + " (" + leveltxt + ")") #write the average calculated from the orig$
f.close()