fix datetime in cleanup.py #2

Manually merged
sum7 merged 2 commits from fix-datetime into master 2021-04-17 17:53:42 +02:00
1 changed files with 17 additions and 3 deletions
Showing only changes of commit 92f91dcf34 - Show all commits

View File

@ -16,6 +16,9 @@ class EjabberdCleanup(EjabberdApiCalls):
self.delete_not_login = True
self.offline_since_days = None
def calc_time_before(self):
return datetime.datetime.now() - datetime.timedelta(days=self.offline_since_days);
def delete_user(self, host, user, reason=""):
if self.dry:
logging.warning(f"{user}@{host}: dry delete : {reason}")
@ -44,13 +47,24 @@ class EjabberdCleanup(EjabberdApiCalls):
except ValueError as err:
logging.error(f"{user}@{host}: not able to parse '{last_stamp}': {err}")
return
if lastdate is not None and lastdate - datetime.datetime.now() > datetime.timedelta(
days=self.offline_since_days
):
if lastdate is None:
logging.error(f"{user}@{host}: not able to parse '{last_stamp}'")
return
elif lastdate < self.calc_time_before():
self.delete_user(host, user, f"last seen @ {lastdate}")
return
else:
logging.debug(f"{user}@{host}: keep @ {lastdate}")
return
logging.debug(f"{user}@{host}: keep")
def run(self):
logging.debug("run with:")
logging.debug(f"dry: {self.dry}")
logging.debug(f"skip by roster: {self.skip_by_roster}")
logging.debug(f"delete not login: {self.delete_not_login}")
logging.debug(f"offline since days: {self.offline_since_days}")
for host in self.fetch_vhosts():
if host in self.ignore_hosts:
continue