cygnal/scripts/purge_old_gcum.py

22 lines
560 B
Python
Raw Normal View History

2018-06-28 15:58:36 +02:00
#!/usr/bin/env python
# coding: utf-8
import os
import sys
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.abspath(os.path.join(SCRIPT_DIRECTORY, '..')))
import arrow
from server.models import db, Report
if __name__ == "__main__":
db.connect()
one_hour_ago = arrow.utcnow().shift(hours=-1).datetime
nb = Report.delete().where(
(Report.type == 'gcum') &
(Report.datetime < one_hour_ago)
).execute()
print("%d GCUM reports purged." % nb)
if not db.is_closed():
db.close()