Skip to content

Commit 181c943

Browse files
Cli TODO app v0.1.2
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.
1 parent 5e60b38 commit 181c943

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cli TODO app <sup>v0.1.0</sup>
1+
# Cli TODO app <sup>v0.1.2</sup>
22

33
Console TODO app.
44

utils/configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Config:
1313
url = 'https://github.com/smartlegionlab/'
1414
copyright_ = 'Copyright © 2024, A.A. Suvorov'
1515
help_url = 'https://github.com/smartlegionlab/todo_app_cli/'
16-
db = 'sqlite' # json | sqlite
16+
db = 'json' # json | sqlite
1717

1818

1919
class TaskQueries:

utils/task_managers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def get_completed_status_text(self, completed_symbol='[✓]', not_completed_symb
5656

5757
class TaskManagerJSON:
5858
def __init__(self, filename='todo.json'):
59-
self.filename = filename
59+
user_home = os.path.expanduser("~")
60+
self.filename = os.path.join(user_home, filename)
6061
self.tasks = []
6162
self.load()
6263

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

146147
class TaskManagerSQLite:
147148
def __init__(self, db_name='todo.db'):
148-
self.db_name = db_name
149+
user_home = os.path.expanduser("~")
150+
self.db_name = os.path.join(user_home, db_name)
149151
self.connection = sqlite3.connect(self.db_name)
150152
self.cursor = self.connection.cursor()
151153
self.create_table()
@@ -184,7 +186,8 @@ def save(self):
184186
def create_task(self, title, description, due_date, completed=False):
185187
title = self.get_unique_title(title)
186188
task = Task(title, description, due_date, completed)
187-
self.cursor.execute(TaskQueries.INSERT_TASK, (task.id, task.title, task.description, task.due_date, task.completed, task.created_at, task.updated_at))
189+
self.cursor.execute(TaskQueries.INSERT_TASK, (task.id, task.title, task.description,
190+
task.due_date, task.completed, task.created_at, task.updated_at))
188191
self.save()
189192
self.tasks = self.load()
190193
return True

0 commit comments

Comments
 (0)