aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcleanup.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/cleanup.py b/cleanup.py
index 4956f94..60eb6ad 100755
--- a/cleanup.py
+++ b/cleanup.py
@@ -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