def add(cls, session, keyword, replace_to): tbl = cls.classes.replace_word(keyword=keyword, replace_to=replace_to) session.add(tbl) try: session.commit() except InvalidRequestError as e: return
def delete(cls, session, id): tbl = cls.classes.replace_word target_record = session.query(tbl).filter_by(id=id).first() session.delete(target_record) try: session.commit() except InvalidRequestError as e: return target_record return target_record
def post(payload: NoteSchema) -> NotesModel: new_note = NotesModel(**payload.dict()) session.add(new_note) session.commit() return new_note
import dht import time from db.session import session from db.models import RoomMetrics from zero.slackbot_settings import DHT11_PIN dht.wiringPiSetup() current_time = int(time.time()) while (True): data_lst = [] start_time = (current_time / 60) * 60 while current_time - start_time < 60: try: data_lst.append( dht.read_dht11(pin=DHT11_PIN) ) except RuntimeError as exc: pass #print exc finally: time.sleep(5) current_time = int(time.time()) # save data if data_lst: humidity, temperature = zip(*data_lst) metric = RoomMetrics( temperature=sum(map(float, temperature)) / len(temperature) + 0.5, humidity=sum(map(float, humidity)) / len(humidity) + 0.5) session.add(metric) session.commit()