fix datetime in cleanup.py
This commit is contained in:
parent
ac0ea074d5
commit
92f91dcf34
20
cleanup.py
20
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
|
||||
|
|
Loading…
Reference in New Issue