commit 0ece98abe8ba6bec400d882cc897353e71790b66
parent 3fe498873110683d19dd084ff2d015c7c318e151
Author: Pr0fiTX <uventik999@gmail.com>
Date: Mon, 16 Jun 2025 21:50:03 +0300
[ADD]: Implement all planned flags
Diffstat:
| M | pydoto.py | | | 15 | ++++++++++----- |
| M | tasksmanage.py | | | 94 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
2 files changed, 96 insertions(+), 13 deletions(-)
diff --git a/pydoto.py b/pydoto.py
@@ -16,18 +16,23 @@ def main():
task.db_append()
return
if args.remove: # -r ID
- pass
+ tm.Task.mark_deleted(args.remove[0])
+ return
if args.done: # -d ID
- pass
+ tm.Task.mark_done(args.done[0])
+ return
if args.print_tasks: # -a
- pass
+ tm.Task.print_tasks()
+ return
if args.print_all: # -A
- pass
+ tm.Task.print_tasks_all()
+ return
if args.id: # -i
tm.Task.print_id()
return
if args.all_id: # -I
- pass
+ tm.Task.print_id_all()
+ return
else:
# Execute witheout any flags
# Prints only ACTIVE tasks
diff --git a/tasksmanage.py b/tasksmanage.py
@@ -21,14 +21,6 @@ class Task:
self.expiration_date = expiration_date
self.status = TaskStatus.ACTIVE
- def complete(self): # TODO: Write From Zero
- if (self.status == TaskStatus.DELETED):
- raise ValueError("!> You can't complete deleted task")
- else:
- self.status = TaskStatus.COMPLETED
-
- return self.status
-
def to_dict(self) -> dict:
return {
"name": self.name,
@@ -46,6 +38,34 @@ class Task:
Task.db_dump(tasks)
@classmethod
+ def mark_done(cls, task_id):
+ tasks = cls.db_load()
+
+ for task in tasks:
+ if (str(task.creation_date) == task_id):
+ if (task.status != TaskStatus.DELETED):
+ task.status = TaskStatus.COMPLETED
+ cls.db_dump(tasks)
+ return
+ else:
+ raise ValueError("!> You can't complete deleted task")
+
+ print("!> Incorrect task ID")
+
+ @classmethod
+ def mark_deleted(cls, task_id):
+ tasks = cls.db_load()
+
+ for task in tasks:
+ if (str(task.creation_date) == task_id):
+ task.status = TaskStatus.DELETED
+ cls.db_dump(tasks)
+ return
+
+ print("!> Incorrect task ID")
+
+
+ @classmethod
def update_expiration_statuses(cls):
tasks = []
tasks_new = []
@@ -146,3 +166,61 @@ class Task:
f" {task.status.value}\t")
print('----' * 30)
+ @classmethod
+ def print_id_all(cls):
+ cls.update_expiration_statuses()
+ tasks = cls.db_load()
+ if not tasks:
+ print("!> You don't have any tasks")
+ return
+
+ print("\n\t=== TASKS ===\n")
+ print(' ID (CREATION DATE)\tTITLE\tDESCRIPTION\tDUE DATE\tSTATUS')
+ print('----' * 30)
+ for task in tasks:
+ print(f" {task.creation_date}\t",
+ f" {task.name}\t",
+ f" {task.description}\t" if task.description else "-\t",
+ f" {task.expiration_date}\t" if task.expiration_date else "-\t",
+ f" {task.status.value}\t")
+ print('----' * 30)
+
+ @classmethod
+ def print_tasks(cls):
+ cls.update_expiration_statuses()
+ tasks = cls.db_load()
+ if not tasks:
+ print("!> You don't have any tasks")
+ return
+
+ print("\n\t=== TASKS ===\n")
+ print(' TITLE\tDESCRIPTION\tDUE DATE\tSTATUS')
+ print('----' * 20)
+ for task in tasks:
+ if (task.status == TaskStatus.DELETED):
+ continue
+
+ print(f" {task.name}\t",
+ f" {task.description}\t" if task.description else "-\t",
+ f" {task.expiration_date}\t" if task.expiration_date else "-\t",
+ f" {task.status.value}\t")
+ print('----' * 20)
+
+ @classmethod
+ def print_tasks_all(cls):
+ cls.update_expiration_statuses()
+ tasks = cls.db_load()
+ if not tasks:
+ print("!> You don't have any tasks")
+ return
+
+ print("\n\t=== TASKS ===\n")
+ print(' TITLE\tDESCRIPTION\tDUE DATE\tSTATUS')
+ print('----' * 20)
+ for task in tasks:
+ print(f" {task.name}\t",
+ f" {task.description}\t" if task.description else "-\t",
+ f" {task.expiration_date}\t" if task.expiration_date else "-\t",
+ f" {task.status.value}\t")
+ print('----' * 20)
+