From bb2807e5fe57baa4b8d33b80efb3c702942f8f14 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Wed, 6 Apr 2022 12:53:27 -0500 Subject: [PATCH] experimenting with datetimes --- README.md | 8 +++++++- database.py | 14 +++++++------- datetime_test.py | 23 +++++++++++++++++++++++ db_util/data.db | Bin 0 -> 12288 bytes database.pyc => db_util/database.pyc | Bin user_input.py | 27 +++++++++++++++------------ 6 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 datetime_test.py create mode 100644 db_util/data.db rename database.pyc => db_util/database.pyc (100%) diff --git a/README.md b/README.md index 3c32a1c..fb2f2b9 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,10 @@ This project is developed as a simple tool for self-motivated individuals working to keep track of their time spent on work. User input is parsed through a CLI written in Python. -Input is then parsed within the project and used to interact with a SQLite database. \ No newline at end of file +Input is then parsed within the project and used to interact with a SQLite database. + +## Instructions for local deployment + +1. Clone this repository +2. From a terminal within the project directory, run ```python3 main.py``` +3. Interact with the project using the CLI. \ No newline at end of file diff --git a/database.py b/database.py index a82931b..6a8a79d 100644 --- a/database.py +++ b/database.py @@ -1,5 +1,6 @@ import sqlite3 from user_input import * +from datetime import datetime # establish a connection to a .db file and create a cursor object con = sqlite3.connect('data.db') @@ -24,20 +25,19 @@ cur.executemany("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", timestamp_list) # 3) Calculate total hours for the week # 4) Calculate complete sum of hours +def create_new_stamp(): + current_time = '' + def get_all_stamps(): return cur.execute("SELECT * FROM TIMESTAMPS;") def get_number_of_stamps(input): table_rows = [] - table_values = cur.execute("SELECT * FROM TIMESTAMPS;") + for row in cur.execute("SELECT * FROM TIMESTAMPS;"): + table_rows.append(row) - iterator = 0 - while (iterator < input): - table_rows.append(table_values[iterator]) - iterator += 1 - - return table_rows + return table_rows[:input] def get_table_length(): diff --git a/datetime_test.py b/datetime_test.py new file mode 100644 index 0000000..e59747e --- /dev/null +++ b/datetime_test.py @@ -0,0 +1,23 @@ +from datetime import datetime +from time import time + +timestamp1 = "Feb 12 08:02:32 2014" +timestamp2 = "Feb 21 11:52:02 2014" + +converted1 = datetime.strptime(timestamp1, "%b %d %H:%M:%S %Y") +converted2 = datetime.strptime(timestamp2, "%b %d %H:%M:%S %Y") + +print(converted1) +print(converted2) + +difference = converted2 - converted1 +days_extracted = difference.days + +print(difference) + +def days_to_minutes(days): + hours = days * 24 + minutes = hours * 60 + return minutes + +print(days_to_minutes(days_extracted)) \ No newline at end of file diff --git a/db_util/data.db b/db_util/data.db new file mode 100644 index 0000000000000000000000000000000000000000..49a92c987c8578e521daa0c516fd268c410db0b6 GIT binary patch literal 12288 zcmeI#y=ucS5C?F{DP-!$=Jm2A5DKL)P&bHR8i!O;hfKz86)K4BV9SM$ezrbVmpUd+ znjve4@E1tFJ7IMGd6IgbS!ZaK7ir??p4~9c*#i+{%xh+^ncdjt7hTdk`Jeby=&{?$ z_hqx|UH!1@RkL6~00Izz00bZa0SG_<0uX=z1pZgRdVSybd41=S*R^?3LaKJ@O{564 zARRo;1hpj^+II@)T1#z1K9Y#XwAX=zHz{}fB*y_009U<00Izz I00eddzn8UF(EtDd literal 0 HcmV?d00001 diff --git a/database.pyc b/db_util/database.pyc similarity index 100% rename from database.pyc rename to db_util/database.pyc diff --git a/user_input.py b/user_input.py index 70351bc..ccdc9ab 100644 --- a/user_input.py +++ b/user_input.py @@ -1,17 +1,25 @@ from database import * +from datetime import datetime user_prompt = """ Welcome to the personal time stamp program. This program is intended to help you keep track of your work hours on personal projects. Please choose from the following options: -1) Select all timestamps (option: limit number of results) -2) Find a timestamp by date range -3) Calculate total hours for the week -4) Calculate complete sum of hours +1) Insert a new timestamp +2) Select all timestamps (option: limit number of results) +3) Find a timestamp by date range +4) Calculate total hours for the week +5) Calculate complete sum of hours """ +# Inner functions detailed below: def handle_first_option(): + current_time = datetime.now() + print(f'Current time: {str(current_time)}') + print("Creating a new timestamp. Enter the following details:") + +def handle_second_option(): limit_results = input("Returning all timestamps. Limit results? y/n \n") if limit_results == 'n': output = get_all_stamps() @@ -57,18 +65,12 @@ def handle_first_option(): elif limit_results != 'y' or limit_results != 'n': print("Please provide a valid selection.") - handle_first_option() + handle_second_option() -def handle_second_option(): - pass - def handle_third_option(): pass -def handle_fourth_option(): - pass - def parse_input(): print(user_prompt) @@ -89,10 +91,11 @@ def parse_input(): print(f'You selected {response}. Working...') - if response == 1: handle_first_option() elif response == 2: + handle_second_option() + elif response == 3: pass elif response == 3: pass