|
from datetime import datetime |
|
import pytz |
|
import os |
|
|
|
def imprimeTime(): |
|
""" |
|
Devuelve la fecha y hora actual en la zona horaria de la Ciudad de México (GMT-6). |
|
""" |
|
|
|
|
|
mexico_city_tz = pytz.timezone('America/Mexico_City') |
|
|
|
|
|
utc_now = datetime.now(pytz.utc) |
|
|
|
|
|
mexico_city_now = utc_now.astimezone(mexico_city_tz) |
|
|
|
|
|
|
|
formatted_time = mexico_city_now.strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
return formatted_time |
|
|
|
def registrar_evento(event_type: str): |
|
""" |
|
Guarda la fecha y hora actual junto con un tipo de evento |
|
en un archivo 'registro.txt' en la raíz del proyecto. |
|
|
|
Args: |
|
event_type (str): Una descripción del tipo de evento a registrar. |
|
""" |
|
|
|
fecha = imprimeTime() |
|
|
|
|
|
file_name = "registro.txt" |
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.abspath(__file__)) |
|
registro_path = os.path.join(script_dir, file_name) |
|
|
|
|
|
|
|
|
|
log_line = f"{fecha},{event_type}\n" |
|
|
|
|
|
try: |
|
with open(registro_path, 'a') as f: |
|
f.write(log_line) |
|
print(f"[{fecha}] Evento '{event_type}' registrado con éxito en '{registro_path}'") |
|
except Exception as e: |
|
print(f"Error al escribir en el archivo de registro '{registro_path}': {e}") |
|
|