Skip to content

Commit

Permalink
Cli TODO app v0.1.2
Browse files Browse the repository at this point in the history
Refactored TaskManager classes to store files in the user's home directory

- Updated TaskManagerJSON to create and load 'todo.json' in the user's home directory.
- Updated TaskManagerSQLite to create and connect to 'todo.db' in the user's home directory.
- Improved application portability by ensuring that file paths are independent of the system's current working directory.
  • Loading branch information
smartlegionlab committed Sep 26, 2024
1 parent 5e60b38 commit 181c943
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cli TODO app <sup>v0.1.0</sup>
# Cli TODO app <sup>v0.1.2</sup>

Console TODO app.

Expand Down
2 changes: 1 addition & 1 deletion utils/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Config:
url = 'https://github.com/smartlegionlab/'
copyright_ = 'Copyright © 2024, A.A. Suvorov'
help_url = 'https://github.com/smartlegionlab/todo_app_cli/'
db = 'sqlite' # json | sqlite
db = 'json' # json | sqlite


class TaskQueries:
Expand Down
9 changes: 6 additions & 3 deletions utils/task_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def get_completed_status_text(self, completed_symbol='[✓]', not_completed_symb

class TaskManagerJSON:
def __init__(self, filename='todo.json'):
self.filename = filename
user_home = os.path.expanduser("~")
self.filename = os.path.join(user_home, filename)
self.tasks = []
self.load()

Expand Down Expand Up @@ -145,7 +146,8 @@ def mark_task_as_completed(self, task_id, completed):

class TaskManagerSQLite:
def __init__(self, db_name='todo.db'):
self.db_name = db_name
user_home = os.path.expanduser("~")
self.db_name = os.path.join(user_home, db_name)
self.connection = sqlite3.connect(self.db_name)
self.cursor = self.connection.cursor()
self.create_table()
Expand Down Expand Up @@ -184,7 +186,8 @@ def save(self):
def create_task(self, title, description, due_date, completed=False):
title = self.get_unique_title(title)
task = Task(title, description, due_date, completed)
self.cursor.execute(TaskQueries.INSERT_TASK, (task.id, task.title, task.description, task.due_date, task.completed, task.created_at, task.updated_at))
self.cursor.execute(TaskQueries.INSERT_TASK, (task.id, task.title, task.description,
task.due_date, task.completed, task.created_at, task.updated_at))
self.save()
self.tasks = self.load()
return True
Expand Down

0 comments on commit 181c943

Please sign in to comment.