From d49aa5da5b9f86b8b101c95b08cdcd49dc07f9a4 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Wed, 6 Apr 2022 13:11:54 -0500 Subject: [PATCH] writes to database --- database.py | 5 +++-- user_input.py | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/database.py b/database.py index 6a8a79d..1596cbb 100644 --- a/database.py +++ b/database.py @@ -25,8 +25,9 @@ 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 create_new_stamp(timestamp, name, purpose): + to_insert = (999, timestamp, 'null', name, purpose) + cur.execute("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", to_insert) def get_all_stamps(): return cur.execute("SELECT * FROM TIMESTAMPS;") diff --git a/user_input.py b/user_input.py index ccdc9ab..c65292a 100644 --- a/user_input.py +++ b/user_input.py @@ -1,5 +1,4 @@ from database import * -from datetime import datetime user_prompt = """ Welcome to the personal time stamp program. @@ -15,9 +14,39 @@ Please choose from the following options: # 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:") + time_of_stamp = datetime.now() + in_out = input("Punching in or out? i/o \n") + + if in_out == 'i': + print("Creating new timestamp and punching in!") + print("Please enter the following details:") + name = input("Your name: ") + purpose = input("Current task: ") + + print("\nPlease confirm your details:") + confirmation = input(f'{name} clocking in at {time_of_stamp} for {purpose}. Confirm? y/n ') + + if confirmation == 'n': + handle_first_option() + elif confirmation == 'y': + create_new_stamp(time_of_stamp, name, purpose) + new_selection = input("Data entered. Make another selection? y/n ") + if new_selection == 'y': + parse_input() + elif new_selection == 'n': + pass + else: + print("Invalid input. Exiting...") + pass + else: + print("Invalid input.") + handle_first_option() + elif in_out == 'o': + print("Punching out.") + else: + print("Invalid input. Please try again:") + handle_first_option() + def handle_second_option(): limit_results = input("Returning all timestamps. Limit results? y/n \n")