#!/usr/bin/python3

import time

tempFileName = "/sys/bus/iio/devices/iio:device0/in_temp_input";
humFileName = "/sys/bus/iio/devices/iio:device0/in_humidityrelative_input";

while True:
    try:
        tempFile = open(tempFileName,"r")
        tempStr =  tempFile.readline()
        tempFile.close()

        humFile = open(humFileName,"r")
        humStr = humFile.readline()
        humFile.close()

        tempC = float(tempStr.strip()) / 1000.0
        tempF = tempC * 9.0 / 5.0 + 32.0
        hum = float(humStr.strip()) / 1000.0

        print("Temperature: {0:.1f}C  {1:.1f}F  Humidity: {2:.1f}%".format(
         tempC,tempF,hum))

        break
    except:
        time.sleep(0.5)