From 271a54aed90daa3676952d96cd382cc75356d692 Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 13:15:01 +0200 Subject: [PATCH 1/8] [unstable] feat: add logs in SQLite --- timer/__main__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/timer/__main__.py b/timer/__main__.py index a7a05ce..a54819e 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -4,6 +4,8 @@ import re import sys import time +from datetime import datetime +import sqlite3 from typing import List, Optional, Tuple, Union import click @@ -135,6 +137,26 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: time_difference_secs = target_time - start_time - 1 + #TODO: add time + message in timer_personal_logs.db + # - in SQLite DB + # OR in text file + # OR send it somewhere for me + + conn = sqlite3.connect('timer_personal_logs.db') + cursor = conn.cursor() + sql_query = ''' + INSERT INTO timer_personal_logs (timestamp, duration, message) + VALUES (?, ?, ?) + ''' + + try: + cursor.execute(sql_query, (datetime.now(), countdown_time_string, message_text)) + conn.commit() + except sqlite3.Error as e: + print(f"An error occurred: {e}") + finally: + conn.close() + try: with Live(display, screen=True) as live: time.sleep(1) From 92055a3967ff399bc43704ff13d275f930c6950f Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 13:50:51 +0200 Subject: [PATCH 2/8] [unstable] feat: create log DB file but does not insert data in it --- README.md | 7 +++++++ timer/__main__.py | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ddc599b..20eebbf 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,13 @@ If you have a suggestion that would make this better, please fork the repo and c - Push to the Branch (`git push origin feature/AmazingFeature`) - Open a Pull Request +## Development + +#### How to start locally: +1) Install deps - `poetry install` +2) Build the project with your changes - `poetry build` +2) Run the project `poetry run timer -m "%message here%" 1m` + ## License This code is distributed under the [Apache-2.0](https://choosealicense.com/licenses/apache-2.0/) license. See `LICENSE` for more information. diff --git a/timer/__main__.py b/timer/__main__.py index a54819e..b87de0f 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -145,13 +145,15 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: conn = sqlite3.connect('timer_personal_logs.db') cursor = conn.cursor() sql_query = ''' - INSERT INTO timer_personal_logs (timestamp, duration, message) + CREATE TABLE IF NOT EXISTS task_logs (timestamp: DATETIME, duration: SMALLTEXT, message: TEXT); + INSERT INTO task_logs (timestamp, duration, message) VALUES (?, ?, ?) ''' try: cursor.execute(sql_query, (datetime.now(), countdown_time_string, message_text)) - conn.commit() + result = conn.commit() + print(f'Result {result}') except sqlite3.Error as e: print(f"An error occurred: {e}") finally: From 3a5b9ad60573ccd703cb3d12f391b5afd135b24c Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 15:09:31 +0200 Subject: [PATCH 3/8] feat: timestamp works well --- timer/__main__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/timer/__main__.py b/timer/__main__.py index b87de0f..ef9eb5a 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -144,16 +144,17 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: conn = sqlite3.connect('timer_personal_logs.db') cursor = conn.cursor() - sql_query = ''' - CREATE TABLE IF NOT EXISTS task_logs (timestamp: DATETIME, duration: SMALLTEXT, message: TEXT); - INSERT INTO task_logs (timestamp, duration, message) - VALUES (?, ?, ?) + create_query = ''' + CREATE TABLE IF NOT EXISTS task_logs (timestamp TEXT, duration TEXT, message TEXT); + ''' + insert_query = ''' + INSERT INTO task_logs (timestamp, duration, message) VALUES (datetime('now'), "LOLs", "KEKS") ''' try: - cursor.execute(sql_query, (datetime.now(), countdown_time_string, message_text)) - result = conn.commit() - print(f'Result {result}') + cursor.execute(create_query) + cursor.execute(insert_query) + conn.commit() except sqlite3.Error as e: print(f"An error occurred: {e}") finally: From cd0adbab022d58645d36b1928ff1a459c52fd7be Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 15:16:47 +0200 Subject: [PATCH 4/8] feat [stable]: writes logs in SQLite --- timer/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timer/__main__.py b/timer/__main__.py index ef9eb5a..e1742f8 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -148,12 +148,12 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: CREATE TABLE IF NOT EXISTS task_logs (timestamp TEXT, duration TEXT, message TEXT); ''' insert_query = ''' - INSERT INTO task_logs (timestamp, duration, message) VALUES (datetime('now'), "LOLs", "KEKS") + INSERT INTO task_logs (timestamp, duration, message) VALUES (datetime('now'), ?, ?) ''' try: cursor.execute(create_query) - cursor.execute(insert_query) + cursor.execute(insert_query, (countdown_time_string, message)) conn.commit() except sqlite3.Error as e: print(f"An error occurred: {e}") From c9b4de2d4c5009921a74aacf924637a485fcfcc9 Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 17:41:55 +0200 Subject: [PATCH 5/8] chore: update README + fix timezone for db --- README.md | 12 +++++++++--- timer/__main__.py | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 20eebbf..2052c2c 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,15 @@ If you have a suggestion that would make this better, please fork the repo and c ## Development #### How to start locally: -1) Install deps - `poetry install` -2) Build the project with your changes - `poetry build` -2) Run the project `poetry run timer -m "%message here%" 1m` +- Build the project with your changes - `poetry build` +- Install deps - `poetry install` +- Run the project `poetry run timer -m "%message here%" 1m` +- Repeat each time you make changes + +###### more traditional way to start: +- (optional) Init your venv - `python -m venv venv` +- (optional) Activate your venv - `source venv/bin/activate` +- Run timer with the flags - `python timer/__main__.py -m 'test message for local dev' 1h38m` ## License diff --git a/timer/__main__.py b/timer/__main__.py index e1742f8..3c9150b 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -138,9 +138,8 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: time_difference_secs = target_time - start_time - 1 #TODO: add time + message in timer_personal_logs.db - # - in SQLite DB # OR in text file - # OR send it somewhere for me + # OR send it somewhere (Slack, obsidian, Gdrive, Notion) conn = sqlite3.connect('timer_personal_logs.db') cursor = conn.cursor() @@ -148,7 +147,7 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: CREATE TABLE IF NOT EXISTS task_logs (timestamp TEXT, duration TEXT, message TEXT); ''' insert_query = ''' - INSERT INTO task_logs (timestamp, duration, message) VALUES (datetime('now'), ?, ?) + INSERT INTO task_logs (timestamp, duration, message) VALUES (datetime('now', 'localtime'), ?, ?) ''' try: From df938f55462e8ff7ec288a7962a405a1ce5e0b1c Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 18:40:55 +0200 Subject: [PATCH 6/8] chore: update version -> 0.1.3 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6c466ba..22f6093 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "timer-cli" -version = "0.1.2" +version = "0.1.3" description = "A simple CLI tool for starting a countdown timer." license = "Apache-2.0" authors = ["Kush Makkapati "] From fe4867c454743e81288b136821c10a7044fa6b59 Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Fri, 19 Jul 2024 18:57:27 +0200 Subject: [PATCH 7/8] feat: add $HOME for log db --- timer/__main__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/timer/__main__.py b/timer/__main__.py index 3c9150b..03e3a4c 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -2,9 +2,9 @@ import math import re +import os import sys import time -from datetime import datetime import sqlite3 from typing import List, Optional, Tuple, Union @@ -141,8 +141,11 @@ def main(duration: Optional[str], no_bell: bool, message: str) -> None: # OR in text file # OR send it somewhere (Slack, obsidian, Gdrive, Notion) - conn = sqlite3.connect('timer_personal_logs.db') + home_dir = os.path.expanduser("~") + db_path = os.path.join(home_dir, "timer_cli_personal_logs.db") + conn = sqlite3.connect(db_path) cursor = conn.cursor() + create_query = ''' CREATE TABLE IF NOT EXISTS task_logs (timestamp TEXT, duration TEXT, message TEXT); ''' From 63f3fd4c54563913ee5457b9f160f0fe6d8910b6 Mon Sep 17 00:00:00 2001 From: Pavel Liferenko Date: Wed, 24 Jul 2024 08:09:57 +0200 Subject: [PATCH 8/8] chore: add Logs description in README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 2052c2c..c71d8f0 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ Use this flag to specify a message to display under the timer. Make sure to surr $ timer 1h30m -m "Review the pull requests" ``` +### Logs + +Every timer you start will be logged and inserted in a DB (SQLite). +Feel free to access this file with any DB management app. +File's location: `$HOME/timer_cli_personal_logs.db` + ## Contributing Contributions are always welcome!