vioott commited on
Commit
212ceaf
·
1 Parent(s): abec8ed

fix: commit pending changes for log reading logic and chat template restart link

Browse files
Files changed (2) hide show
  1. logs.py +15 -7
  2. templates/chat.html +1 -1
logs.py CHANGED
@@ -25,13 +25,21 @@ def get_user_history(user_id: int) -> dict:
25
  with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
26
  lines = f.readlines()
27
 
28
- current_user = None
29
-
30
- for line in lines:
31
- if line.startswith("Usuário:"):
32
- current_user = int(line.split(":")[1].strip())
33
- elif line.startswith("Histórico:") and current_user == user_id:
34
- history = eval(line.split(":", 1)[1].strip())
 
 
 
 
 
 
 
 
35
 
36
  except FileNotFoundError:
37
  pass
 
25
  with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
26
  lines = f.readlines()
27
 
28
+ # Itera de trás para frente para pegar a entrada mais recente
29
+ for i in range(len(lines) - 1, -1, -1):
30
+ line = lines[i]
31
+ # Procura pela linha de Usuário
32
+ if line.startswith(f"Usuário: {user_id}"):
33
+ # Se achou o usuário, procura o histórico nas linhas seguintes (que no reverse são anteriores)
34
+ # Mas como a estrutura é fixa (Usuário -> Histórico), o Histórico está na linha i+1
35
+ if i + 1 < len(lines) and lines[i+1].startswith("Histórico:"):
36
+ try:
37
+ history_str = lines[i+1].split(":", 1)[1].strip()
38
+ history = eval(history_str)
39
+ return history # Retorna imediatamente a última versão encontrada
40
+ except Exception as e:
41
+ print(f"Erro ao ler histórico: {e}")
42
+ continue
43
 
44
  except FileNotFoundError:
45
  pass
templates/chat.html CHANGED
@@ -6,7 +6,7 @@
6
  </head>
7
  <body>
8
  <div class="navbar">
9
- <a href="/">🏠 Início</a>
10
  <a href="/perfil/{{ user_id }}">👤 Perfil</a>
11
  </div>
12
 
 
6
  </head>
7
  <body>
8
  <div class="navbar">
9
+ <a href="/">🏠 Recomeçar</a>
10
  <a href="/perfil/{{ user_id }}">👤 Perfil</a>
11
  </div>
12