From 3ed65b57002b5ebf1a1e93540a515eae51bbbf77 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Wed, 6 Apr 2022 13:55:21 -0500 Subject: [PATCH] update for punch out works --- data.db | Bin 12288 -> 12288 bytes database.py | 18 ++++++++---------- user_input.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/data.db b/data.db index f1b57cff85cb6c2189eaf06dbb2818afa5f054f5..a7cb204fc6ea4c1229b1944e287e709868d71e4c 100644 GIT binary patch delta 107 zcmZojXh@hK%_ucd#+gxSW5N=CHb(w!4E) delta 130 zcmZojXh@hK&B#Ad#+i|SW5N=CE@uA44E&Gy5AZMEEGRIQKUSKVje&tdRlYbsH#I*m zRUtK}I5j0TsWd%3GcR3%2_&hkotIyt;G3D9SecVpo?n!$ke{beP?VpQnp`5o2vQ-f Kja_z;f&c)%HYa%i diff --git a/database.py b/database.py index 30867c2..daaac12 100644 --- a/database.py +++ b/database.py @@ -10,16 +10,6 @@ cur = con.cursor() cur.execute("CREATE TABLE IF NOT EXISTS TIMESTAMPS (session_id INTEGER PRIMARY KEY, time_in STRING, time_out STRING, name STRING, purpose STRING);") cur.execute("CREATE TABLE IF NOT EXISTS USERS (id INTEGER PRIMARY KEY, name STRING, cumulative_hours INTEGER);") -# declare and insert some initial values -timestamp_list = [ - ('Mikayla', 'work on project'), - ('not Mikayla', 'work on project'), - ('someone else', 'debugging') -] - -cur.executemany("INSERT INTO TIMESTAMPS (name, purpose) VALUES (?, ?)", timestamp_list) -con.commit() - # Functions to define: # 1) Select all timestamps # 2) Find a timestamp by date range @@ -31,6 +21,14 @@ def create_new_stamp(timestamp, name, purpose): cur.execute("INSERT INTO TIMESTAMPS (time_in, name, purpose) VALUES (?, ?, ?)", to_insert) con.commit() +def punch_out(timestamp, id): + data = (timestamp, id) + cur.execute("""UPDATE TIMESTAMPS + SET time_out = ? + WHERE session_id = ? + """, data) + con.commit() + def get_all_stamps(): return cur.execute("SELECT * FROM TIMESTAMPS;") diff --git a/user_input.py b/user_input.py index 15488d8..df43be4 100644 --- a/user_input.py +++ b/user_input.py @@ -1,4 +1,5 @@ from database import * +from datetime import * user_prompt = """ Welcome to the personal time stamp program. @@ -15,10 +16,10 @@ Please choose from the following options: # Inner functions detailed below: def handle_first_option(): - time_of_stamp = datetime.now() in_out = input("Punching in or out? i/o \n") if in_out == 'i': + time_of_stamp = datetime.now() print("Creating new timestamp and punching in!") print("Please enter the following details:") name = input("Your name: ") @@ -43,7 +44,12 @@ def handle_first_option(): print("Invalid input.") handle_first_option() elif in_out == 'o': - print("Punching out.") + time_of_stamp = datetime.now() + print("Preparing to punch out.") + session = input("Please provide your session ID." ) + punch_out(time_of_stamp, session) + print("Punch out successful. Returning...") + parse_input() else: print("Invalid input. Please try again:") handle_first_option()