diff options
author | Geno <geno+dev@fireorbit.de> | 2020-10-11 11:18:48 +0200 |
---|---|---|
committer | Geno <geno+dev@fireorbit.de> | 2020-12-19 14:42:59 +0100 |
commit | 92f91dcf34efb2b0ddc505c0fa573f2306b1620f (patch) | |
tree | 70a6949ee024b62aacd97def83e1968338d7bd16 | |
parent | ac0ea074d5684ac4f22b7787ce3b95f77f25e3e6 (diff) |
fix datetime in cleanup.py
-rwxr-xr-x | cleanup.py | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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 |