def time_command(t=-1, description=""): """ Starts a timer, optionally give a description and specify the task id you are working on. """ c = conn() active_timers = Timer.active_timers(c) if len(active_timers) > 0: # List the existing timer(s) and show elapsed times for timer in active_timers: if timer.description: description = timer.description else: description = "" if timer.task_id: task_id = "Task %4d." % timer.task_id else: task_id = "No task assigned." print "Timer %04d. %s %s %s" % (timer.id, timer.elapsed_time(), task_id, description) else: # Create a new timer. if t > 0: task_id = t else: task_id = None if len(description) == 0: description = None if not description and not task_id: print "No active timers. To create a new timer please specify either a description or a task id." else: time = Timer.create(c, task_id=task_id, description=description, started_at=datetime.now()) print "Timer %s Started" % time.id
def stop_command(t=-1): c = conn() if t > 0: # stop the particular timer specified timers = [t] else: # stop all timers (there's probably just 1) timers = Timer.active_timers(c) if len(timers) == 0: print "No timers running." for timer in timers: Timer.stop(c, timer.id) print "Stopped timer %04d total time %s" % (timer.id, timer.elapsed_time())