unitink72

Well Known Member
Thought I would share this in case anyone else finds it useful.

I wrote a very simple time logging script in python. You run it, and it just sits there asking when you want to start the timer. After starting, you can either cancel or end. And if you end, you can put in a comment. It produces a csv file that you can read in excel:

Start Time, End Time, Elapsed Time, Comment
2016-11-16 20:27:01, 2016-11-16 22:33:47, 7605, inventory
2016-11-17 20:11:47, 2016-11-17 22:34:23, 8555, inventory done
2016-11-18 09:08:02, 2016-11-18 12:17:45, 11382, 6-2 VS spar


Here is the code. You may want to customize logFileName. I run this on linux, hence the unix-style path.

Code:
import datetime
import os.path

logFileName = '/home/tink/rv/rvWorkLog.txt'
userIn = ''
startTime = 0
endTime   = 0

if not os.path.isfile(logFileName):
     print('Log does not exist %s' % logFileName)
     userIn = input ('Create it? [Y/N]  ')
     if 'y' in userIn or 'Y' in userIn:
          logF = open(logFileName, 'w+')
          logF.write('Start Time, End Time, Elapsed Time, Comment\n')
          logF.close()
     else:
          exit ('Exiting')


while (1):
     while ('s' not in userIn):
          userIn = input ('[s]tart          ')

     startTime = datetime.datetime.now()

     while ('e' not in userIn and 'c' not in userIn):
          userIn = input ('[e]nd [c]ancel   ')
     
     if 'c' in userIn:
          continue

     endTime = datetime.datetime.now()
     userIn = input ('Comment          ')
     logF = open(logFileName, 'a')
     logF.write('%s, %s, %s, %s\n' % (startTime.strftime('%Y-%m-%d %H:%M:%S'), \
                                      endTime.strftime('%Y-%m-%d %H:%M:%S'),   \
                                      (endTime - startTime).seconds,           \
                                      userIn))
     userIn = ''
     logF.close()
#end while