Raphael Maenle
0284eb2fa8
- device now last field 'last connection' which gets updated at every server connection from the respective device - manual cleanup script in database deletes all devices which have never been updated, or have a timestamp older than 30 days
15 lines
409 B
Python
15 lines
409 B
Python
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()
|
|
|