Created
July 16, 2013 04:21
-
-
Save markwatson/6005739 to your computer and use it in GitHub Desktop.
A simple time tracker script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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