FOOD-AI / registro.py
caissaa23's picture
Create registro.py
22a4ec3 verified
import json
import os
# Nombre del archivo donde se guardar谩 tu informaci贸n
ARCHIVO_REGISTRO = "registro_personal.json"
# Funci贸n para guardar el estado completo
def guardar_registro(estado):
"""
Guarda todo el estado personal en un archivo JSON.
- estado: diccionario con todas tus variables (calor铆as, comidas, actividad, hidrataci贸n, sue帽o, estr茅s, etc.)
"""
try:
with open(ARCHIVO_REGISTRO, "w") as f:
json.dump(estado, f, indent=4, default=str) # default=str para datetime
return True
except Exception as e:
print(f"Error al guardar registro: {e}")
return False
# Funci贸n para cargar el estado desde el archivo
def cargar_registro():
"""
Carga el estado desde el archivo JSON.
Devuelve un diccionario vac铆o si no existe el archivo.
"""
if os.path.exists(ARCHIVO_REGISTRO):
try:
with open(ARCHIVO_REGISTRO, "r") as f:
estado = json.load(f)
return estado
except Exception as e:
print(f"Error al cargar registro: {e}")
return {}
else:
# Si no existe, devolver un estado vac铆o
return {}
# Funci贸n para reiniciar el registro (opcional)
def reiniciar_registro():
"""
Borra todo el historial y el archivo de registro.
"""
if os.path.exists(ARCHIVO_REGISTRO):
os.remove(ARCHIVO_REGISTRO)
return {}