Created
September 14, 2018 02:37
-
-
Save mhagiwara/4ab6d2a1ecf9b1579516c50d70d8864f to your computer and use it in GitHub Desktop.
Pomodoro timer in command line with 50 lines of Python
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 python3 | |
import os | |
import time | |
import sys | |
from datetime import datetime | |
import pyscreenshot | |
from PIL import Image | |
from tqdm import tqdm | |
tqdm.monitor_interval = 0 | |
def show_notification(title, body): | |
os.system('osascript -e \'display notification "%s" with title "%s"\'' % (body, title)) | |
def capture_and_save(shrink_factor=8): | |
im = pyscreenshot.grab() | |
width, height = im.size | |
im = im.resize((width // shrink_factor, height // shrink_factor), Image.LANCZOS) | |
timestamp = datetime.now().strftime('%Y%m%d-%H%M%S') | |
filename = 'images/%s.png' % timestamp | |
im.save(filename) | |
def main(num_pomodori): | |
for i in range(1, num_pomodori + 1): | |
print('Pomodoro #%i (started on %s)' % (i, datetime.now().strftime('%Y%m%d-%H%M%S'))) | |
show_notification('pomo', 'work started') | |
# pomorodo | |
for _ in tqdm(range(25), ncols=80): | |
time.sleep(60) | |
capture_and_save() | |
# break | |
show_notification('pomo', 'break started') | |
for _ in tqdm(range(5), ncols=80): | |
time.sleep(60) | |
capture_and_save() | |
if __name__ == '__main__': | |
if len(sys.argv) >= 2: | |
num_pomodori = int(sys.argv[1]) | |
else: | |
num_pomodori = 4 | |
main(num_pomodori) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment