checks that index array is populated before considering a user 'active'

This commit is contained in:
chiptune 2023-06-27 07:29:38 -05:00
parent 893d8b6413
commit 3f45ac68d8
1 changed files with 7 additions and 2 deletions

View File

@ -19,14 +19,19 @@ class Utils:
return str(datetime.datetime.utcnow())
def list_active_users():
"""returns a list of all users having a slog index"""
"""returns a list of all users having a (populated) slog index"""
active_users = []
for homedir in os.listdir("/home/"):
if "." in homedir:
continue
try:
if "index" in os.listdir(f"/home/{homedir}/.slog/"):
active_users.append(homedir)
# check if index is not empty
with open(f"/home/{homedir}/.slog/index", "r", encoding="utf-8") as indexfile:
index_data = json.loads(indexfile.read())
if len(index_data) != 0:
active_users.append(homedir)
except (FileNotFoundError, PermissionError):
pass