experimenting with datetimes

This commit is contained in:
Mikayla Dobson
2022-04-06 12:53:27 -05:00
parent 1880b60602
commit bb2807e5fe
6 changed files with 52 additions and 20 deletions

View File

@@ -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. 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. 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. 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.

View File

@@ -1,5 +1,6 @@
import sqlite3 import sqlite3
from user_input import * from user_input import *
from datetime import datetime
# establish a connection to a .db file and create a cursor object # establish a connection to a .db file and create a cursor object
con = sqlite3.connect('data.db') con = sqlite3.connect('data.db')
@@ -24,20 +25,19 @@ cur.executemany("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", timestamp_list)
# 3) Calculate total hours for the week # 3) Calculate total hours for the week
# 4) Calculate complete sum of hours # 4) Calculate complete sum of hours
def create_new_stamp():
current_time = ''
def get_all_stamps(): def get_all_stamps():
return cur.execute("SELECT * FROM TIMESTAMPS;") return cur.execute("SELECT * FROM TIMESTAMPS;")
def get_number_of_stamps(input): def get_number_of_stamps(input):
table_rows = [] table_rows = []
table_values = cur.execute("SELECT * FROM TIMESTAMPS;") for row in cur.execute("SELECT * FROM TIMESTAMPS;"):
table_rows.append(row)
iterator = 0 return table_rows[:input]
while (iterator < input):
table_rows.append(table_values[iterator])
iterator += 1
return table_rows
def get_table_length(): def get_table_length():

23
datetime_test.py Normal file
View File

@@ -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))

BIN
db_util/data.db Normal file

Binary file not shown.

View File

@@ -1,17 +1,25 @@
from database import * from database import *
from datetime import datetime
user_prompt = """ user_prompt = """
Welcome to the personal time stamp program. Welcome to the personal time stamp program.
This program is intended to help you keep track of your work hours on personal projects. This program is intended to help you keep track of your work hours on personal projects.
Please choose from the following options: Please choose from the following options:
1) Select all timestamps (option: limit number of results) 1) Insert a new timestamp
2) Find a timestamp by date range 2) Select all timestamps (option: limit number of results)
3) Calculate total hours for the week 3) Find a timestamp by date range
4) Calculate complete sum of hours 4) Calculate total hours for the week
5) Calculate complete sum of hours
""" """
# Inner functions detailed below:
def handle_first_option(): 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") limit_results = input("Returning all timestamps. Limit results? y/n \n")
if limit_results == 'n': if limit_results == 'n':
output = get_all_stamps() output = get_all_stamps()
@@ -57,18 +65,12 @@ def handle_first_option():
elif limit_results != 'y' or limit_results != 'n': elif limit_results != 'y' or limit_results != 'n':
print("Please provide a valid selection.") print("Please provide a valid selection.")
handle_first_option() handle_second_option()
def handle_second_option():
pass
def handle_third_option(): def handle_third_option():
pass pass
def handle_fourth_option():
pass
def parse_input(): def parse_input():
print(user_prompt) print(user_prompt)
@@ -89,10 +91,11 @@ def parse_input():
print(f'You selected {response}. Working...') print(f'You selected {response}. Working...')
if response == 1: if response == 1:
handle_first_option() handle_first_option()
elif response == 2: elif response == 2:
handle_second_option()
elif response == 3:
pass pass
elif response == 3: elif response == 3:
pass pass