-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from MeuHubPython/pomodoro
Python Simple Pomodoro Timer
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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
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) | ||
|
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
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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Python 3.10.12 |