The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Automate your to-do list with Python

Managing daily tasks can become overwhelming without an organized system. Automating your to-do list with Python can drastically improve productivity by streamlining task management and reducing manual effort. Here’s a comprehensive guide to creating a Python-based automated to-do list that not only organizes tasks but also helps prioritize, update, and even send reminders.


Why Automate Your To-Do List?

Manual to-do lists, whether on paper or in apps, require consistent input and updating. Automation allows you to:

  • Automatically add, update, and remove tasks.

  • Prioritize tasks based on deadlines or importance.

  • Get notifications or reminders.

  • Integrate with calendars or emails.

  • Save time and reduce human error.

Python, with its simplicity and powerful libraries, is an ideal language to build such a system.


Step 1: Setting Up Your Project Environment

Begin by creating a virtual environment and installing necessary packages. For this automation, consider the following packages:

  • sqlite3 (built-in) for storing tasks.

  • datetime for handling dates and times.

  • schedule for task scheduling.

  • smtplib for sending email reminders (optional).

  • tabulate to print tasks neatly in the console.

You can install schedule and tabulate via pip:

bash
pip install schedule tabulate

Step 2: Designing the To-Do List Database

Storing tasks in a local database makes management easier and persistent. SQLite is lightweight and requires no server.

Database schema for tasks:

  • id: unique identifier.

  • task: description of the task.

  • priority: integer to represent importance (1-highest, 3-lowest).

  • due_date: deadline for the task.

  • status: pending or completed.

Create the database and table:

python
import sqlite3 conn = sqlite3.connect('todo.db') cursor = conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS tasks ( id INTEGER PRIMARY KEY AUTOINCREMENT, task TEXT NOT NULL, priority INTEGER NOT NULL, due_date TEXT, status TEXT NOT NULL CHECK(status IN ('pending', 'completed')) ) ''') conn.commit() conn.close()

Step 3: Adding Tasks

Create a function to add new tasks into the database:

python
def add_task(task, priority=3, due_date=None): conn = sqlite3.connect('todo.db') cursor = conn.cursor() cursor.execute( 'INSERT INTO tasks (task, priority, due_date, status) VALUES (?, ?, ?, ?)', (task, priority, due_date, 'pending') ) conn.commit() conn.close()

Example usage:

python
add_task("Finish the monthly report", 1, "2025-05-20") add_task("Call the client", 2)

Step 4: Viewing and Prioritizing Tasks

To view tasks sorted by priority and due date:

python
from tabulate import tabulate def view_tasks(show_completed=False): conn = sqlite3.connect('todo.db') cursor = conn.cursor() if show_completed: cursor.execute('SELECT * FROM tasks ORDER BY priority, due_date') else: cursor.execute('SELECT * FROM tasks WHERE status="pending" ORDER BY priority, due_date') tasks = cursor.fetchall() conn.close() if tasks: headers = ["ID", "Task", "Priority", "Due Date", "Status"] print(tabulate(tasks, headers=headers, tablefmt='pretty')) else: print("No tasks to show.")

Step 5: Updating and Completing Tasks

Marking tasks as completed or updating details:

python
def update_task(task_id, task=None, priority=None, due_date=None, status=None): conn = sqlite3.connect('todo.db') cursor = conn.cursor() fields = [] values = [] if task: fields.append("task = ?") values.append(task) if priority: fields.append("priority = ?") values.append(priority) if due_date: fields.append("due_date = ?") values.append(due_date) if status: fields.append("status = ?") values.append(status) values.append(task_id) query = f"UPDATE tasks SET {', '.join(fields)} WHERE id = ?" cursor.execute(query, values) conn.commit() conn.close()

To mark a task completed:

python
update_task(1, status="completed")

Step 6: Automating Reminders

Using the schedule library, automate daily reminders for tasks due today or overdue.

python
import schedule import time from datetime import datetime def send_reminder(): today = datetime.now().strftime("%Y-%m-%d") conn = sqlite3.connect('todo.db') cursor = conn.cursor() cursor.execute(''' SELECT id, task, due_date FROM tasks WHERE status="pending" AND due_date <= ? ORDER BY due_date ''', (today,)) tasks_due = cursor.fetchall() conn.close() if tasks_due: print("Reminder: You have tasks due today or overdue!") for t in tasks_due: print(f"Task ID: {t[0]}, Task: {t[1]}, Due: {t[2]}") else: print("No pending tasks due today.") # Schedule the reminder to run daily at 9:00 AM schedule.every().day.at("09:00").do(send_reminder) while True: schedule.run_pending() time.sleep(60)

Step 7: Sending Email Notifications (Optional)

You can extend the reminder system to email you the list of due tasks.

python
import smtplib from email.mime.text import MIMEText def send_email(subject, body, to_email): from_email = "your_email@example.com" password = "your_email_password" msg = MIMEText(body) msg['Subject'] = subject msg['From'] = from_email msg['To'] = to_email with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp: smtp.login(from_email, password) smtp.send_message(msg) def email_reminder(): today = datetime.now().strftime("%Y-%m-%d") conn = sqlite3.connect('todo.db') cursor = conn.cursor() cursor.execute(''' SELECT task, due_date FROM tasks WHERE status="pending" AND due_date <= ? ORDER BY due_date ''', (today,)) tasks_due = cursor.fetchall() conn.close() if tasks_due: body = "Tasks due today or overdue:n" for task, due_date in tasks_due: body += f"- {task} (Due: {due_date})n" send_email("To-Do List Reminder", body, "recipient_email@example.com")

Step 8: Creating a Simple CLI Interface

To interact with your to-do list, create a command-line interface:

python
def main(): while True: print("n1. Add Taskn2. View Tasksn3. Update Taskn4. Exit") choice = input("Select an option: ") if choice == '1': task = input("Task description: ") priority = int(input("Priority (1-3): ")) due_date = input("Due date (YYYY-MM-DD) or leave blank: ") due_date = due_date if due_date else None add_task(task, priority, due_date) print("Task added.") elif choice == '2': view_tasks() elif choice == '3': task_id = int(input("Task ID to update: ")) print("Leave blank if no change.") task = input("New task description: ") priority = input("New priority (1-3): ") due_date = input("New due date (YYYY-MM-DD): ") status = input("Status (pending/completed): ") update_task( task_id, task=task if task else None, priority=int(priority) if priority else None, due_date=due_date if due_date else None, status=status if status else None ) print("Task updated.") elif choice == '4': break else: print("Invalid option. Try again.") if __name__ == "__main__": main()

Final Thoughts

Automating your to-do list with Python provides full control over task management and opens endless possibilities for customization. By integrating database storage, scheduling reminders, and optionally adding email notifications, you can maintain an efficient workflow without manual overhead. As you grow more comfortable, consider extending this system with GUI apps, mobile integration, or web interfaces.

This automated approach not only saves time but also keeps you consistently on top of your responsibilities.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About