Created
March 15, 2016 20:59
-
-
Save mekhami/4829c2ef011c74530df7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| """Usage: | |
| pymodoro start <taskname> [--minutes=<minutes>] | |
| Options: | |
| --version Show program's version number and exit | |
| -h, --help Show this help message and exit | |
| """ | |
| import time | |
| import datetime | |
| from docopt import docopt | |
| class Timer(object): | |
| def __init__(self, minutes=30): | |
| self.seconds = minutes * 60 | |
| self.complete = False | |
| @property | |
| def current_time(self): | |
| return str(datetime.timedelta(seconds=self.seconds)) | |
| def start(self): | |
| while self.seconds > 0: | |
| print('\r'+self.current_time, end=" ") | |
| time.sleep(1) | |
| self.seconds -= 1 | |
| self.complete = True | |
| class Task(object): | |
| def __init__(self, name, timer): | |
| self.name = name | |
| self.timer = timer | |
| def start(self): | |
| print('Timer for {} has started! \n'.format(self.name)) | |
| try: | |
| self.timer.start() | |
| while not self.timer.complete: | |
| time.sleep(1) | |
| self.finish() | |
| except KeyboardInterrupt: | |
| self.finish(completed=False) | |
| def finish(self, completed=True): | |
| if completed: | |
| print("\nTask completed!") | |
| else: | |
| print("\nTask interrupted.") | |
| if __name__ == '__main__': | |
| args = docopt(__doc__, version='Pymodoro 1.0') | |
| try: | |
| mytimer = Timer(float(args['--minutes'])) | |
| except KeyError: | |
| mytimer = Timer() | |
| mytask = Task(args['<taskname>'], mytimer) | |
| mytask.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment