diff --git a/README.md b/README.md index ddc599b..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! @@ -54,6 +60,19 @@ 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: +- 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 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/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 "] diff --git a/timer/__main__.py b/timer/__main__.py index a7a05ce..03e3a4c 100644 --- a/timer/__main__.py +++ b/timer/__main__.py @@ -2,8 +2,10 @@ import math import re +import os import sys import time +import sqlite3 from typing import List, Optional, Tuple, Union import click @@ -135,6 +137,31 @@ 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 + # OR in text file + # OR send it somewhere (Slack, obsidian, Gdrive, Notion) + + 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); + ''' + insert_query = ''' + INSERT INTO task_logs (timestamp, duration, message) VALUES (datetime('now', 'localtime'), ?, ?) + ''' + + try: + cursor.execute(create_query) + cursor.execute(insert_query, (countdown_time_string, message)) + 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)