def add_reading(celsius, fahrenheit): """ Adds a reading to the database :param celsius: :param fahrenheit: :return: """ sql = 'INSERT INTO `readings` (`location`, `reading_time`, `celsius`, ' \ '`fahrenheit`) VALUES (%(location)s, %(now)s, %(celsius)s, ' \ '%(fahrenheit)s)' data = { 'location': get_config('location', 'UNKNOWN'), 'now': datetime.now(), 'celsius': celsius, 'fahrenheit': fahrenheit, } execute(sql, data)
return round(celsius, 2), round(fahrenheit, 2) def add_reading(celsius, fahrenheit): """ Adds a reading to the database :param celsius: :param fahrenheit: :return: """ sql = 'INSERT INTO `readings` (`location`, `reading_time`, `celsius`, ' \ '`fahrenheit`) VALUES (%(location)s, %(now)s, %(celsius)s, ' \ '%(fahrenheit)s)' data = { 'location': get_config('location', 'UNKNOWN'), 'now': datetime.now(), 'celsius': celsius, 'fahrenheit': fahrenheit, } execute(sql, data) if __name__ == '__main__': while True: readings = get_temperature() if readings: add_reading(*readings) sleep(get_config('interval', 60))