from server import db import time from database.models import Device def cleanDevices(): allDevs = db.session.query(Device) devices = allDevs.filter(Device.lastConnection <= int(round(time.time())) - 60*60*24*30).all() devices += allDevs.filter(Device.lastConnection == None) for device in devices: print(device.deviceName) db.session.delete(device) db.session.commit()