Skip to content

Instantly share code, notes, and snippets.

View minorsecond's full-sized avatar

Robert Ross Wardrup minorsecond

View GitHub Profile
def time_formatter():
"""
Takes user input as 00:00, splits those using : as seperator,
and prints the time formatted for timesheet in tenths of an
hour
"""
time_input = raw_input("\nTime Formatter\n" \
"Please enter hours and minutes worked today" \
"in 00:00 format: ")
if len(time_input.split(':')) == 2:
@minorsecond
minorsecond / Time_formatter
Created April 13, 2015 19:25
Tenths of hours between two times
def get_time(time):
return datetime.datetime.strptime(time, '%I:%M %p')
def total_time():
t_in = get_time(raw_input("Please enter your start time in 00:00 format: "))
t_out = get_time(raw_input("Please enter your end time in 00:00 format: "))
delta = t_out - t_in
HOUR = 60 * 60
delta_tenths = float(delta.seconds // (HOUR / 10)) / 10
@minorsecond
minorsecond / Main Menu
Created April 16, 2015 09:46
Main menu - causes error in Python3: "SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 11-12: malformed \N character escape
print('PYPER Timesheet Utility \n \n' \
'What would you like to do? \n' \
'1. Clock In\New Job\n' \
'2. Switch Job\n' \
'3. Break Time\Quit\n' \
'4. Set up jobs/break types\n' \
'5. Timesheet Minute Formatter\n' \
'6. Calculate Total Time Worked\n' \
'7. Generate Today\'s Timesheet\n' \
'8. Quit\n')
@minorsecond
minorsecond / jobdb commit
Created April 18, 2015 00:14
Not creating the DB for some reason.
with jobdb:
if debug == 1:
print("DEBUGGING")
print("Connected to jobdb. Data to be inserted into JOBDB Database:")
print ("Lead Name: {0}, Job Name: {1}, Job Abbrev: {2}, Time Worked: {3}, Date: {4}, UUID: {5}")\
.format(lead_name, job_name,job_abbrev, time, date, p_uuid)
cur.execute(
"INSERT INTO jobdb(UUID, Lead_name, Job_name, Job_abbrev, Time_worked, "
"Date) VALUES(?, ?, ?, ?, ?, ?)", [p_uuid, lead_name, job_name, job_abbrev, time, date]
)
@minorsecond
minorsecond / Update ClocktimesTable
Last active August 29, 2015 14:19
Broken Sqlalchemy Code
now = datetime.datetime.now()
out = session.query(Clocktime). \
filter(Clocktime.p_uuid == p_uuid). \
update({"time_out": now}, synchronize_session='fetch')
session.commit()
@minorsecond
minorsecond / tc.py_traceback
Created April 22, 2015 23:55
tc.py_traceback
Traceback (most recent call last):
File "/home/rwardrup/Dev/Timeclock/tc.py", line 518, in <module>
main_menu()
File "/home/rwardrup/Dev/Timeclock/tc.py", line 489, in main_menu
breaktime()
File "/home/rwardrup/Dev/Timeclock/tc.py", line 207, in breaktime
update(Clocktime.time_out == datetime.datetime.now())
File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2938, in update
self, synchronize_session, values, update_args)
File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1184, in factory
@minorsecond
minorsecond / key_iter
Created April 25, 2015 11:07
key_iter
for p_uuid in session.query(Clocktime.p_uuid).distinct():
times_dict = {'ID': p_uuid, 't_worked': 0}
print(times_dict)
@minorsecond
minorsecond / time_sum.py
Created April 28, 2015 22:57
Sanity Check: Get sum of time worked (t_worked) of each row in sqlite database.
t_worked = session.query(Clocktime).filter(Clocktime.p_uuid == p_uuid).order_by(Clocktime.id.desc()).all()
for i in tworked:
_sum_time += i.t_worked
eg. I want sum of time for p_uuid==1, _sum_time should equal '8'.
p_uuid t_worked
===================
1 1
@minorsecond
minorsecond / tc.py
Last active August 29, 2015 14:20
Broken function in tc.py. It runs but does not calculate _sum_time correctly. If tworked is > .1, funky things happen.For example, in the job table.. "worked" held 0.2. When .2 was supposed to be added to it, .2 was written again.I suspect my logic is incorrect but I can't find it. Help please?
def clockout():
"""
Clocks user out of project. Prints time_out (now) to clocktimes table for whichever row contains the same
p_uuid created in project_start().
:rtype : object
:return:
"""
if status == 0:
raw_input("You're not currently in a job. Press enter to return to main menu")
@minorsecond
minorsecond / tc.py
Created April 30, 2015 11:16
Broken function in tc.py. It runs but does not calculate _sum_time correctly. If tworked is > .1, funky things happen.For example, in the job table.. "worked" held 0.2. When .2 was supposed to be added to it, .2 was written again.I suspect my logic is incorrect but I can't find it. Help please?
def clockout():
"""
Clocks user out of project. Prints time_out (now) to clocktimes table for whichever row contains the same
p_uuid created in project_start().
:rtype : object
:return:
"""
if status == 0:
raw_input("You're not currently in a job. Press enter to return to main menu")