Task Manager Project — Round 1
Two classes. One system.
Task — knows its own data. Title, priority, status, deadline, timestamp.
TaskList — owns the tasks. Adds them, saves them, loads them, displays them.
We design both from scratch — OOP from the first line.
The Task class
import datetime
class Task:
VALID_PRIORITIES = ["low", "medium", "high"]
VALID_STATUSES = ["pending", "in progress", "done"]
def __init__(self, title, priority, deadline):
self.title = title
self.priority = priority
self.status = "pending"
self.deadline = deadline
self.created = datetime.datetime.now().strftime("%Y-%m-%d,%H:%M:%S")
def __str__(self):
return f"[{self.status.upper()}] {self.title} | priority: {self.priority} | deadline: {self.deadline}"
def __repr__(self):
return f"Task('{self.title}', '{self.priority}', '{self.deadline}')"
Status defaults to "pending" — every new task starts there. Creation timestamp is automatic — same pattern as the Calories Tracker. __str__ gives us readable output immediately.
task = Task("Write report", "high", "2025-05-01")
print(task)
Output → [PENDING] Write report | priority: high | deadline: 2025-05-01
The TaskList class
class TaskList:
def __init__(self, name):
self.name = name
self.tasks = {}
self.filename = f"{name}.txt"
def __str__(self):
total = len(self.tasks)
pending = sum(1 for t in self.tasks.values() if t.status == "pending")
done = sum(1 for t in self.tasks.values() if t.status == "done")
return f"{self.name} — {total} tasks | {pending} pending | {done} done"
def __len__(self):
return len(self.tasks)
TaskList("daily") creates a task list that saves to daily.txt. Same pattern as Shelter — independent instances, independent files.
Get next ID
def get_next_id(self):
if not self.tasks:
return 1
return max(self.tasks.keys()) + 1
IDs are integers — no conversion needed. Clean and simple.
Add a task
def add(self):
title = ""
while not title:
title = input("Task title: ")
priority = ""
while priority not in Task.VALID_PRIORITIES:
priority = input("Priority (low/medium/high): ").lower()
deadline = ""
while not deadline:
deadline = input("Deadline (YYYY-MM-DD): ")
id = self.get_next_id()
task = Task(title, priority, deadline)
self.tasks[id] = task
with open(self.filename, "a", encoding="utf-8") as f:
f.write(f"{id};{task.title};{task.priority};{task.status};{task.deadline};{task.created}\n")
self.load()
The task is created as a Task object — stored in self.tasks and written to file. Same two-step pattern from Safe Paws.
Load from file
def load(self):
self.tasks = {}
try:
with open(self.filename, "r", encoding="utf-8") as f:
for line in f:
row = line.strip().split(";")
task = Task(row[1], row[2], row[4])
task.status = row[3]
task.created = row[5]
self.tasks[int(row[0])] = task
except FileNotFoundError:
pass
Display all tasks
def show(self):
if not self.tasks:
print("No tasks yet.")
return
for id, task in self.tasks.items():
print(f"{id}. {task}")
The menu — Round 1
task_list = TaskList("daily")
task_list.load()
print(task_list)
while True:
print("\nTask Manager")
option = input("1-Add task\n2-Show all\nq-Quit\nChoose: ")
if option == "1":
task_list.add()
print("Task added successfully!")
elif option == "2":
task_list.show()
elif option == "q":
break
else:
print("Invalid option.")
A simulation — after adding three tasks:
daily — 3 tasks | 3 pending | 0 done
1. [PENDING] Write report | priority: high | deadline: 2025-05-01
2. [PENDING] Buy groceries | priority: low | deadline: 2025-04-30
3. [PENDING] Review code | priority: medium | deadline: 2025-05-02
Two classes. A working task manager. Persistence included.
Round 2 — update status, filter by priority, export report.