fix stuff
Andronaco Marco marco.andronaco@olivetti.com
Thu, 21 Sep 2023 14:50:43 +0200
2 files changed,
13 insertions(+),
7 deletions(-)
M
backend_iot/db.py
→
backend_iot/db.py
@@ -68,7 +68,7 @@
return get_aqi_owm(latitude, longitude) db.connect() -db.create_tables([Record]) +db.create_tables([Record, AQI]) def getLatestRecord(): #User.select().order_by(User.id.desc()).get()
M
backend_iot/views.py
→
backend_iot/views.py
@@ -1,15 +1,18 @@
from backend_iot import app from backend_iot.db import getLatestRecord, addRecord, get_aqi from flask import request, redirect, render_template, abort +from playhouse.shortcuts import model_to_dict from datetime import datetime current_latitude, current_longitude = 45.46437891252755, 7.872049153560152 def update_record(record): - record["latitude"] = current_latitude - record["longitude"] = current_longitude - record["timestamp"] = datetime.now() - record["aqi"] = get_aqi(current_latitude, current_longitude) + record.update() + record.latitude = current_latitude + record.longitude = current_longitude + record.timestamp = datetime.now() + record.aqi = get_aqi(current_latitude, current_longitude) + return record def latest_or_abort(): latest = getLatestRecord()@@ -40,5 +43,8 @@ if key == "fan_speed" and latest["auto"]:
continue latest[key] = form[key] - update_record(latest) - addRecord(**latest)+ new_record = update_record(latest) + temp = model_to_dict(new_record) + del temp["id"] + addRecord(**temp) + return temp