Last active
April 18, 2017 21:45
-
-
Save epochblue/7d75c4d3a2de65870be2fe52eb221de0 to your computer and use it in GitHub Desktop.
A simple command line Pomodoro timer.
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
#!/usr/bin/env python3 | |
""" | |
Just a simple command line timer for the Pomodoro Technique. | |
More info: https://en.wikipedia.org/wiki/Pomodoro_Technique | |
Usage: `pomodoro.py` | |
Author: Bill Israel <[email protected]> | |
""" | |
import os | |
import sys | |
import time | |
import subprocess | |
TASK_SOUND = os.path.abspath('/System/Library/Sounds/Glass.aiff') | |
BREAK_SOUND = os.path.abspath('/System/Library/Sounds/Ping.aiff') | |
TASK = 0 | |
SHORT_BREAK = 1 | |
LONG_BREAK = 2 | |
FULL_POMODORO = ( | |
(TASK, 25, TASK_SOUND), (SHORT_BREAK, 5, BREAK_SOUND), | |
(TASK, 25, TASK_SOUND), (SHORT_BREAK, 5, BREAK_SOUND), | |
(TASK, 25, TASK_SOUND), (SHORT_BREAK, 5, BREAK_SOUND), | |
(TASK, 25, TASK_SOUND), (LONG_BREAK, 15, BREAK_SOUND) | |
) | |
MESSAGES = { | |
TASK: 'Get to work!', | |
LONG_BREAK: 'Take a long break, you earned it.', | |
SHORT_BREAK: 'Take a quick break.' | |
} | |
def pomodoro(): | |
for interval, duration, sound in FULL_POMODORO: | |
subprocess.call(['afplay', sound]) | |
msg = MESSAGES[interval] | |
time_remaining = int(duration * 60) | |
while time_remaining >= 0: | |
minutes_remaining = time_remaining // 60 | |
seconds_remaining = time_remaining % 60 | |
if not time_remaining: | |
print('\x1b[2K\r{msg} (Done.)'.format(msg=msg), end='', flush=True) | |
else: | |
print('\x1b[2K\r{msg} ({minutes:02d}:{seconds:02d} remaining)'.format( | |
msg=msg, | |
minutes=minutes_remaining, | |
seconds=seconds_remaining | |
), end='', flush=True) | |
time_remaining -= 1 | |
time.sleep(1) | |
print() | |
if __name__ == '__main__': | |
try: | |
pomodoro() | |
except KeyboardInterrupt: | |
print('\x1b[2K\rPomodoro abandoned.') | |
sys.exit(130) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment