diff --git a/database.py b/database.py index 6ed3e92..7d4ebef 100644 --- a/database.py +++ b/database.py @@ -1,5 +1,4 @@ import sqlite3 -from typing import ParamSpecArgs from user_input import * # establish a connection to a .db file and create a cursor object @@ -19,26 +18,6 @@ timestamp_list = [ cur.executemany("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", timestamp_list) - -""" - -# The below logic for testing initial values are inserted, -# are able to be queried, -# and are accurately represented in the table. - -# query table below: -table_rows = [] -for row in cur.execute("SELECT * FROM TIMESTAMPS;"): - # print each result - print(row) - # store each result individually in the list above - table_rows.append(row) - -# find COUNT(*) for the table -print(len(table_rows)) - -""" - # Functions to define: # 1) Select all timestamps # 2) Find a timestamp by date range @@ -46,7 +25,19 @@ print(len(table_rows)) # 4) Calculate complete sum of hours def get_all_stamps(): - pass + return cur.execute("SELECT * FROM TIMESTAMPS;") + +def get_number_of_stamps(input): + table_rows = [] + for row in cur.execute("SELECT * FROM TIMESTAMPS;"): + table_rows.append(row) + + +def get_table_length(): + table_rows = [] + for row in cur.execute("SELECT * FROM TIMESTAMPS;"): + table_rows.append(row) + return len(table_rows) def get_stamp_by_date(): pass diff --git a/user_input.py b/user_input.py index b5e6ace..d0eae35 100644 --- a/user_input.py +++ b/user_input.py @@ -1,16 +1,69 @@ +from database import * + 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 +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 """ +def handle_first_option(): + limit_results = input("Returning all timestamps. Limit results? y/n \n") + if limit_results == 'n': + output = get_all_stamps() + for row in output: + print(row) + + elif limit_results == 'y': + def find_row_limit(): + user_limit = input("How many rows? \n") + table_length = get_table_length() + try: + user_limit = int(user_limit) + except ValueError: + print("Please provide an integer.") + find_row_limit() + except: + print("An unknown error occurred. Please try again.") + find_row_limit() + + if type(user_limit) is int: + print(f'Returning first {user_limit} rows of data...') + + + find_row_limit() + + elif limit_results != 'y' or limit_results != 'n': + print("Please provide a valid selection.") + handle_first_option() + def parse_input(): print(user_prompt) response = input("Enter your selection: ") - print(f'You selected {response}. Working...') \ No newline at end of file + try: + response = int(response) + except ValueError: + print("Please provide an integer.") + parse_input() + except: + print("Please provide a valid input.") + parse_input() + + if type(response) == int: + print(f'You selected {response}. Working...') + + if response == 1: + handle_first_option() + elif response == 2: + pass + elif response == 3: + pass + elif response == 4: + pass + else: + pass \ No newline at end of file