Skip to content

Instantly share code, notes, and snippets.

@PageotD
Last active June 22, 2022 18:53
Show Gist options
  • Save PageotD/031c07a497656ec13a5bd67c471ef8af to your computer and use it in GitHub Desktop.
Save PageotD/031c07a497656ec13a5bd67c471ef8af to your computer and use it in GitHub Desktop.
A simple Pomodoro script in Python
import time
import chime
from rich.progress import Progress
def ptimer(phase, ptime, pcolor="white"):
"""
A generic timer for the three phases of the pomodoro
technique.
phase: (str) name of the phase
ptime: (int) duration of the phase in minutes
pcolor: (str, default "white") color to display for the phase name in terminal
"""
with Progress() as progress:
# Initialize the progress bar
task = progress.add_task("[{}]{:<15}".format(pcolor, phase), total=ptime)
# Update the progress bar until time is up
while not progress.finished:
progress.update(task, advance=0.25)
time.sleep(0.25)
# Initialize checkmarks
checkmarks = 0
# Initialize chime with material theme
chime.theme('material')
# Loop
while checkmarks < 4:
# Increment checkmarks
checkmarks += 1
# Print the current cycle iteration
print("Cycle {}/4".format(checkmarks))
# Work phase 20 minutes
ptimer("Work!", 25*60, pcolor="green")
chime.info()
# Break phase
if checkmarks == 4:
# Long break 15 minutes
ptimer("Long break!", 15*60, pcolor="red")
chime.success()
else:
# Short break 5 minutes
ptimer("Short break!", 5*60, pcolor="magenta")
chime.info()
# A small time.sleep(1) to allow chime.success to run before the script ends
time.sleep(1)
print("You did it! Well done :)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment