Spaces:
Sleeping
Sleeping
feat(log): add get_all_users function
Browse files
logs.py
CHANGED
|
@@ -24,7 +24,7 @@ def get_user_history(user_id: int) -> dict:
|
|
| 24 |
lines = f.readlines()
|
| 25 |
|
| 26 |
current_user = None
|
| 27 |
-
|
| 28 |
for line in lines:
|
| 29 |
if line.startswith("Usuário:"):
|
| 30 |
current_user = int(line.split(":")[1].strip())
|
|
@@ -35,3 +35,29 @@ def get_user_history(user_id: int) -> dict:
|
|
| 35 |
pass
|
| 36 |
|
| 37 |
return history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
lines = f.readlines()
|
| 25 |
|
| 26 |
current_user = None
|
| 27 |
+
|
| 28 |
for line in lines:
|
| 29 |
if line.startswith("Usuário:"):
|
| 30 |
current_user = int(line.split(":")[1].strip())
|
|
|
|
| 35 |
pass
|
| 36 |
|
| 37 |
return history
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def get_all_users() -> dict:
|
| 41 |
+
"""
|
| 42 |
+
Retorna todos os usuários e seus históricos a partir do arquivo de log.
|
| 43 |
+
"""
|
| 44 |
+
users = {}
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
with open("recommender.log", "r", encoding="utf-8") as f:
|
| 48 |
+
lines = f.readlines()
|
| 49 |
+
|
| 50 |
+
current_user = None
|
| 51 |
+
|
| 52 |
+
for i, line in enumerate(lines):
|
| 53 |
+
|
| 54 |
+
if line.startswith("Usuário:"):
|
| 55 |
+
current_user = int(line.split(":")[1].strip())
|
| 56 |
+
elif line.startswith("Histórico:") and current_user is not None:
|
| 57 |
+
history = eval(line.split(":", 1)[1].strip())
|
| 58 |
+
users[current_user] = history
|
| 59 |
+
|
| 60 |
+
except FileNotFoundError:
|
| 61 |
+
pass
|
| 62 |
+
|
| 63 |
+
return users
|