caissaa23 commited on
Commit
22a4ec3
verified
1 Parent(s): 53dee06

Create registro.py

Browse files
Files changed (1) hide show
  1. registro.py +46 -0
registro.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ # Nombre del archivo donde se guardar谩 tu informaci贸n
5
+ ARCHIVO_REGISTRO = "registro_personal.json"
6
+
7
+ # Funci贸n para guardar el estado completo
8
+ def guardar_registro(estado):
9
+ """
10
+ Guarda todo el estado personal en un archivo JSON.
11
+ - estado: diccionario con todas tus variables (calor铆as, comidas, actividad, hidrataci贸n, sue帽o, estr茅s, etc.)
12
+ """
13
+ try:
14
+ with open(ARCHIVO_REGISTRO, "w") as f:
15
+ json.dump(estado, f, indent=4, default=str) # default=str para datetime
16
+ return True
17
+ except Exception as e:
18
+ print(f"Error al guardar registro: {e}")
19
+ return False
20
+
21
+ # Funci贸n para cargar el estado desde el archivo
22
+ def cargar_registro():
23
+ """
24
+ Carga el estado desde el archivo JSON.
25
+ Devuelve un diccionario vac铆o si no existe el archivo.
26
+ """
27
+ if os.path.exists(ARCHIVO_REGISTRO):
28
+ try:
29
+ with open(ARCHIVO_REGISTRO, "r") as f:
30
+ estado = json.load(f)
31
+ return estado
32
+ except Exception as e:
33
+ print(f"Error al cargar registro: {e}")
34
+ return {}
35
+ else:
36
+ # Si no existe, devolver un estado vac铆o
37
+ return {}
38
+
39
+ # Funci贸n para reiniciar el registro (opcional)
40
+ def reiniciar_registro():
41
+ """
42
+ Borra todo el historial y el archivo de registro.
43
+ """
44
+ if os.path.exists(ARCHIVO_REGISTRO):
45
+ os.remove(ARCHIVO_REGISTRO)
46
+ return {}