Skip to content

Instantly share code, notes, and snippets.

@markwatson
Created July 16, 2013 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markwatson/6005739 to your computer and use it in GitHub Desktop.
Save markwatson/6005739 to your computer and use it in GitHub Desktop.
A simple time tracker script.
#/usr/bin/env python
"""
time_cards.py
This utility tracks time.
"""
import datetime
import atexit
log_file = r'H:\recorded_time.csv'
log_file_handle = open(log_file, 'a')
def log(message):
when = datetime.datetime.now()
log_file_handle.write("%s,%s\n" % (when.strftime("%Y%m%d%H%M%S"), message))
log_file_handle.flush()
print " --> %s at %s" % (message,when.strftime("%m/%d %H:%M:%S"))
return when
def commands():
print """Here are the commands:
q) Quit
s) Step Out
r) Returned
n) New Task
"""
def main():
clean_exit = False
def exit_handler():
if not clean_exit:
log("Left")
log_file_handle.close()
atexit.register(exit_handler)
print "Welcome to the time recorder."
commands()
quit = False
status = 'here'
log("Arrived")
while not quit:
c = raw_input("command> ").strip()
if len(c) == 1:
if c == 'q':
quit = True
clean_exit = True
log("Left")
elif c == 's':
if status == 'here':
status = 'gone'
log("Stepped Out")
else:
print "You're already gone."
elif c == 'r':
if status == 'gone':
status = 'here'
log("Returned")
else:
print "You're already here."
elif c == 'n':
task = raw_input("task> ")
log("Started task: '%s'" % (task,))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment