Beispiel #1
0
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)
Beispiel #2
0
    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))