Skip to content

Commit

Permalink
Merge pull request #40 from MeuHubPython/pomodoro
Browse files Browse the repository at this point in the history
Python Simple Pomodoro Timer
  • Loading branch information
king04aman authored Oct 22, 2024
2 parents 7b47319 + 7736b46 commit 2f010f6
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Pomodoro Timer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Pomodoro Timer

A simple, customizable command line pomodoro timer built in Python.

## Features

- Customizable work, short and long breaks intervals: Define your own durations for each cycle.
- Pause whenever you want: Pause the timer when you want to take a break.
- Cycles: Run Multiple cycles of work and break intervals
- Console output: Show work and break intervals in the console.

## How it works

The Pomodoro Timer follow these steps:
1. Set your work and break intervals.
2. Take a short break every work interval.
3. After a set number of cycles, take a long break.

## Usage

1. Clone this repository to your machine.
2. Run the Python script from the command line.
'''python pomodoro_timer.py'''

## Author

[MeuHubPython](https://github.com/MeuHubPython)

72 changes: 72 additions & 0 deletions Pomodoro Timer/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import time


def countdown(minutes, label):
total_seconds = minutes * 60
while total_seconds:
mins, secs = divmod(total_seconds, 60)
timer = f"{mins:02d}:{secs:02d}"
print(f"{label} Timer: {timer}", end="\r")
time.sleep(1)
total_seconds -= 1
print(f"\n{label} finished!")


def handle_pause_stop():
while True:
user_input = input(
"\nPress 'p' to pause, 's' to stop, or 'Enter' to continue: "
).lower()
if user_input == "p":
print("Timer paused. Press 'Enter' to resume.")
input()
elif user_input == "s":
print("Timer stopped.")
return True # Return True to signal that the timer should stop
else:
return False # Return False to continue with the timer


def pomodoro_timer(work_min, short_break_min, long_break_min, cycles):
for i in range(cycles):
print(f"\nCycle {i+1} of {cycles}")
countdown(work_min, "Work")
if i < cycles - 1:
print("\nStarting short break...")
if handle_pause_stop():
return
countdown(short_break_min, "Short Break")
else:
print("\nStarting long break...")
if handle_pause_stop():
return
countdown(long_break_min, "Long Break")
if not repeat_or_end():
return


def repeat_or_end():
user_input = input(
"\nCycle finished. Would you like to repeat the cycle? (y/n): "
).lower()
return user_input == "y"


def get_valid_input(prompt):
while True:
try:
value = int(input(prompt))
if value <= 0:
raise ValueError
return value
except ValueError:
print("Invalid input. Please enter a positive integer.")


if __name__ == "__main__":
work_minutes = get_valid_input("Enter work interval in minutes: ")
short_break_minutes = get_valid_input("Enter short break interval in minutes: ")
long_break_minutes = get_valid_input("Enter long break interval in minutes: ")
cycles = get_valid_input("Enter the number of cycles: ")

pomodoro_timer(work_minutes, short_break_minutes, long_break_minutes, cycles)
1 change: 1 addition & 0 deletions Pomodoro Timer/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 3.10.12

0 comments on commit 2f010f6

Please sign in to comment.