Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/FranksGP/Gestor_de_tareas/llms.txt

Use this file to discover all available pages before exploring further.

This page documents every function defined in index.py. Each entry covers the exact signature as it appears in the source, all parameters, what the function returns, any file I/O or console output it produces, and how it responds to errors. The functions fall into three categories: persistence helpers (cargarTask, guardarTask), task-manipulation functions (agregarTask, listarTask, tareaCompletada, delete_task), and the top-level entry point (main).

cargarTask()

def cargarTask():
Reads Tareas.json from the current working directory and deserialises it into a Python list. If the file does not exist, or if its contents cannot be parsed as valid JSON, the function returns an empty list rather than raising an exception, keeping all callers safe from I/O and parse errors. Return value: list — a list of task dictionaries, or [] when the file is absent or malformed. Side effects: Opens Tareas.json in read mode ("r") if the file exists. Error handling: A json.JSONDecodeError is caught internally; the function returns [] instead of propagating the exception. A missing file is detected with os.path.exists() before any open attempt, so no FileNotFoundError is raised.
# Load the current task list at startup
tasks = cargarTask()
print(f"Loaded {len(tasks)} task(s).")

guardarTask(tasks)

def guardarTask(tasks):
Serialises the supplied task list and writes it to Tareas.json, completely overwriting any previous content. The file is written with a four-space indent so it remains human-readable.
tasks
list
required
A list of task dictionaries. Each dictionary must contain the keys titulo (str), descripcion (str), and completed (bool). Passing an empty list is valid and will write [] to the file.
Return value: None Side effects: Opens Tareas.json in write mode ("w"), creating the file if it does not exist or truncating it if it does. Uses json.dump(tasks, file, indent=4). Error handling: No explicit error handling — any OSError raised by the underlying open() call (e.g., a permission error) will propagate to the caller.
tasks = cargarTask()
tasks[0]["completed"] = True
guardarTask(tasks)   # Persists the change immediately

agregarTask(titulo, descripcion)

def agregarTask(titulo, descripcion):
Creates a new task dictionary and appends it to the existing task list, then saves the updated list back to disk. Every new task starts with completed set to False. After saving, a confirmation message is printed to standard output.
titulo
string
required
The title of the new task. This is a short, human-readable label displayed when tasks are listed.
descripcion
string
required
A longer description of the task. Displayed alongside the title in the task list.
Return value: None Side effects:
  • Calls cargarTask() to read the current list from disk.
  • Appends {"titulo": titulo, "descripcion": descripcion, "completed": False} to the list.
  • Calls guardarTask() to write the updated list to Tareas.json.
  • Prints "Tarea agregada exitosamente." to standard output.
Error handling: Inherits the error behaviour of cargarTask() and guardarTask().
agregarTask("Revisar correos", "Leer y responder mensajes pendientes")
# Console: Tarea agregada exitosamente.

listarTask()

def listarTask():
Reads the current task list and prints each task to standard output in a numbered format. When the list is empty, a dedicated message is printed instead. This function is also called internally by main() before prompting for an index in options 3 and 4. Return value: None Side effects:
  • Calls cargarTask() to retrieve the current list.
  • If the list is empty, prints "No hay tareas disponibles." and returns immediately.
  • Otherwise, iterates with enumerate(tasks, start=1) and prints each task in the format:
{index}. {titulo} - {descripcion} [{status}]
where {status} is "✔ Completada" when task["completed"] is True, or "✘ Pendiente" when it is False. Error handling: Relies on cargarTask() for safe file reading; no additional error handling needed.
listarTask()
# Example output:
# 1. Comprar leche - Ir al supermercado por la tarde [✘ Pendiente]
# 2. Estudiar Python - Repasar funciones y manejo de archivos [✔ Completada]

tareaCompletada(index)

def tareaCompletada(index):
Marks a single task as completed by setting its completed field to True. The index argument uses 1-based numbering to match what listarTask() displays to the user.
index
integer
required
The 1-based position of the task to mark as completed. Must satisfy 0 < index <= len(tasks). If the value is out of range, an error message is printed and no changes are saved.
Return value: None Side effects:
  • Calls cargarTask() to load the current list.
  • If index is valid, sets tasks[index - 1]["completed"] = True, calls guardarTask(), and prints "Tarea marcada como completada.".
  • If index is out of range, prints "Índice inválido." without modifying the file.
Error handling: Validates the index with 0 < index <= len(tasks). A ValueError for non-integer input is not handled here — it is caught in main() before this function is called.
tareaCompletada(1)
# Console (valid index):   Tarea marcada como completada.
# Console (invalid index): Índice inválido.

delete_task(index)

def delete_task(index):
Permanently removes a task from the list by its 1-based index and saves the updated list to disk. The title of the deleted task is echoed back to the user as confirmation.
index
integer
required
The 1-based position of the task to delete. Must satisfy 0 < index <= len(tasks). If the value is out of range, an error message is printed and the list is not modified.
Return value: None Side effects:
  • Calls cargarTask() to load the current list.
  • If index is valid, calls tasks.pop(index - 1) to remove the task, calls guardarTask(), and prints "Tarea '{titulo}' eliminada." where {titulo} is the title of the removed task.
  • If index is out of range, prints "Índice inválido." without modifying the file.
Error handling: Same index-range check as tareaCompletada. ValueError for non-integer input is handled upstream in main().
delete_task(2)
# Console (valid index):   Tarea 'Estudiar Python' eliminada.
# Console (invalid index): Índice inválido.

main()

def main():
The interactive entry point for the application. Runs an infinite while True loop that displays a five-option menu, reads a string from standard input, and dispatches to the appropriate function. The loop exits cleanly when the user chooses option 5. Return value: None Side effects:
  • Prints the menu to standard output on every iteration:
    Gestor de Tareas
    1. Agregar tarea
    2. Listar tareas
    3. Marcar tarea como completada
    4. Eliminar tarea
    5. Salir
    
  • Option 1: Prompts for a title and description, calls agregarTask().
  • Option 2: Calls listarTask().
  • Option 3: Calls listarTask(), prompts for an integer index, calls tareaCompletada(). Catches ValueError if the input is not a valid integer and prints "Entrada inválida. Debe ingresar un número.".
  • Option 4: Calls listarTask(), prompts for an integer index, calls delete_task(). Catches ValueError with the same message as option 3.
  • Option 5: Prints "Saliendo..." and breaks out of the loop.
  • Any other input: Prints "Opción inválida, intente de nuevo." and continues the loop.
Error handling: ValueError exceptions from int() conversions in options 3 and 4 are caught with a try/except block inside the loop. All other error handling is delegated to the functions called.
if __name__ == "__main__":
    main()

Build docs developers (and LLMs) love