diff options
author | genofire <geno+dev@fireorbit.de> | 2020-06-29 19:34:48 +0200 |
---|---|---|
committer | genofire <geno+dev@fireorbit.de> | 2020-06-29 19:34:48 +0200 |
commit | 091b6e525aacad1abf8d800338d242141dec11c2 (patch) | |
tree | 73137b27409b00a45c76c2bfbf4b5e9d029a4ff1 /cleanup.py | |
parent | 1256ea7de8a093f51b116f2802871480cd646ae8 (diff) | |
parent | 044e0334d2bfb9c4b076afc562e4fb3d17c7db20 (diff) |
Merge branch 'add-ci' into 'master'
Add ci
See merge request sum7/ejabberd-tools!6
Diffstat (limited to 'cleanup.py')
-rwxr-xr-x | cleanup.py | 40 |
1 files changed, 21 insertions, 19 deletions
@@ -20,16 +20,16 @@ class EjabberdCleanup(EjabberdApiCalls): if self.dry: logging.warning(f"{user}@{host}: dry delete : {reason}") else: - self.cmd("unregister", {"host": host, "user": user}) + self.cmd("unregister", {"host": host, "user": user}) logging.warning(f"{user}@{host}: deleted - {reason}") def run_user(self, host, user): if self.skip_by_roster: - roster = self.cmd("get_roster",{"host": host, "user": user}) + roster = self.cmd("get_roster", {"host": host, "user": user}) if len(roster) > 0: logging.debug(f"{user}@{host}: skipped it has a roster") return - last = self.cmd("get_last",{"host": host, "user": user}) + last = self.cmd("get_last", {"host": host, "user": user}) if self.delete_not_login and last["status"] == "Registered but didn't login": self.delete_user(host, user, "not login") return @@ -37,14 +37,16 @@ class EjabberdCleanup(EjabberdApiCalls): last_stamp = last["timestamp"] lastdate = None try: - lastdate = datetime.datetime.strptime(last_stamp,"%Y-%m-%dT%H:%M:%SZ") - except: + lastdate = datetime.datetime.strptime(last_stamp, "%Y-%m-%dT%H:%M:%SZ") + except: # noqa: E722 try: - lastdate = datetime.datetime.strptime(last_stamp,"%Y-%m-%dT%H:%M:%S.%fZ") - except: + lastdate = datetime.datetime.strptime(last_stamp, "%Y-%m-%dT%H:%M:%S.%fZ") + except: # noqa: E722 logging.error(f"{user}@{host}: not able to parse '{last_stamp}'") return - if lastdate != None and lastdate-datetime.datetime.now() > datetime.timedelta(days=self.offline_since_days): + if lastdate is not None and lastdate - datetime.datetime.now() > datetime.timedelta( + days=self.offline_since_days + ): self.delete_user(host, user, f"last seen @ {lastdate}") return @@ -53,7 +55,7 @@ class EjabberdCleanup(EjabberdApiCalls): if host in self.ignore_hosts: continue logging.info(f"run cleanup for host: {host}") - for user in self.cmd("registered_users",{"host": host}): + for user in self.cmd("registered_users", {"host": host}): if user in self.ignore_usernames: continue self.run_user(host, user) @@ -64,20 +66,20 @@ if __name__ == "__main__": # load config config = Config() - if config.get('debug', default=False): + if config.get("debug", default=False): logging.getLogger().setLevel(logging.DEBUG) # credentials and parameters - url = config.get('url', default='http://localhost:5280/api') - login = config.get('login', default=None) - api = config.get('api', default='rest') + url = config.get("url", default="http://localhost:5280/api") + login = config.get("login", default=None) + api = config.get("api", default="rest") # init handler cleaner = EjabberdCleanup(url, login, api) - cleaner.dry = config.get('cleaner_dry',default=False) - cleaner.ignore_hosts = config.get('cleaner_ignore_hosts',default=[]) - cleaner.ignore_usernames = config.get('cleaner_ignore_usernames',default=[]) - cleaner.skip_by_roster = config.get('cleaner_skip_by_roster',default=True) - cleaner.delete_not_login = config.get('cleaner_delete_not_login',default=True) - cleaner.offline_since_days = config.get('cleaner_offline_since_days', default=None) + cleaner.dry = config.get("cleaner_dry", default=False) + cleaner.ignore_hosts = config.get("cleaner_ignore_hosts", default=[]) + cleaner.ignore_usernames = config.get("cleaner_ignore_usernames", default=[]) + cleaner.skip_by_roster = config.get("cleaner_skip_by_roster", default=True) + cleaner.delete_not_login = config.get("cleaner_delete_not_login", default=True) + cleaner.offline_since_days = config.get("cleaner_offline_since_days", default=None) cleaner.run() |