update for punch out works

This commit is contained in:
Mikayla Dobson
2022-04-06 13:55:21 -05:00
parent 6b5484f640
commit 3ed65b5700
3 changed files with 16 additions and 12 deletions

BIN
data.db

Binary file not shown.

View File

@@ -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 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);") 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: # Functions to define:
# 1) Select all timestamps # 1) Select all timestamps
# 2) Find a timestamp by date range # 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) cur.execute("INSERT INTO TIMESTAMPS (time_in, name, purpose) VALUES (?, ?, ?)", to_insert)
con.commit() 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(): def get_all_stamps():
return cur.execute("SELECT * FROM TIMESTAMPS;") return cur.execute("SELECT * FROM TIMESTAMPS;")

View File

@@ -1,4 +1,5 @@
from database import * from database import *
from datetime import *
user_prompt = """ user_prompt = """
Welcome to the personal time stamp program. Welcome to the personal time stamp program.
@@ -15,10 +16,10 @@ Please choose from the following options:
# Inner functions detailed below: # Inner functions detailed below:
def handle_first_option(): def handle_first_option():
time_of_stamp = datetime.now()
in_out = input("Punching in or out? i/o \n") in_out = input("Punching in or out? i/o \n")
if in_out == 'i': if in_out == 'i':
time_of_stamp = datetime.now()
print("Creating new timestamp and punching in!") print("Creating new timestamp and punching in!")
print("Please enter the following details:") print("Please enter the following details:")
name = input("Your name: ") name = input("Your name: ")
@@ -43,7 +44,12 @@ def handle_first_option():
print("Invalid input.") print("Invalid input.")
handle_first_option() handle_first_option()
elif in_out == 'o': 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: else:
print("Invalid input. Please try again:") print("Invalid input. Please try again:")
handle_first_option() handle_first_option()