def get_temperature(self): # Temperature regex (make sure we only match temperature) temp_regex = r'\d{2}\.\d{2}' response = hw_controller.get_temperature(self.mac) if not re.match(temp_regex, str(response)): response = self.fallback_temperature(self.mac) return float(response)
def main(): macs = [] args = [] conn = sqlite3.connect('home/pi/dbs/temperature.db') c = conn.cursor() create_temp = "CREATE TABLE IF NOT EXISTS heating temperature (timestamp timestamp, mac text, temperature real)" c.execute(create_temp) query = """INSERT INTO heating_temperature (timestamp, mac, temperature) VALUES (?,?,?)""" for mac in macs: temp = hw_controller.get_temperature(mac) args.push_back((time.time(), mac, temperature,)) c.executemany(query, args) conn.commit() conn.close()