From 90db6bbd6704247fce70f485b7901bc4ccf219a8 Mon Sep 17 00:00:00 2001 From: moiSentineL Date: Sat, 3 Aug 2024 13:19:41 +0530 Subject: [PATCH] add feature to update duration --- flomo/cli.py | 5 +++-- flomo/tracker.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/flomo/cli.py b/flomo/cli.py index cd94115..bf7a5f3 100644 --- a/flomo/cli.py +++ b/flomo/cli.py @@ -132,13 +132,14 @@ def delete(session_ids: Tuple): @click.argument("session_id") @click.option("-t", "--tag", help="Session Tag") @click.option("-n", "--name", help="Session Name") -def update(session_id: str, tag: str | None, name: str | None): +@click.option("-d", "--duration", help="Total Duration") +def update(session_id: str, tag: str | None, name: str | None, duration: str | None): """ Update session data. """ try: db = tracker.Tracker() - db.update_session(session_id, tag, name) + db.update_session(session_id, tag, name, duration) db.conn.close() except ( errors.DBFileNotFoundError, diff --git a/flomo/tracker.py b/flomo/tracker.py index b1e4f6f..a5201f2 100644 --- a/flomo/tracker.py +++ b/flomo/tracker.py @@ -92,7 +92,7 @@ def delete_session(self, session_ids: Tuple[str] | Tuple): ) self.conn.commit() - def update_session(self, session_id: str, tag: str | None, name: str | None): + def update_session(self, session_id: str, tag: str | None, name: str | None, duration: str | None): if not self.get_session(session_id): raise errors.NoSessionError(session_id) @@ -106,6 +106,11 @@ def update_session(self, session_id: str, tag: str | None, name: str | None): "UPDATE sessions SET name = ? WHERE id = ?", (name, session_id) ) print(f'Name updated to "{name}" for session {session_id}') + if duration: + self.cursor.execute( + "UPDATE sessions SET total_time = ? WHERE id = ?", (duration, session_id) + ) + print(f'Duration updated to "{duration}" for session {session_id}') self.conn.commit()