Skip to content

Commit 2f010f6

Browse files
authored
Merge pull request #40 from MeuHubPython/pomodoro
Python Simple Pomodoro Timer
2 parents 7b47319 + 7736b46 commit 2f010f6

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

Pomodoro Timer/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Pomodoro Timer
2+
3+
A simple, customizable command line pomodoro timer built in Python.
4+
5+
## Features
6+
7+
- Customizable work, short and long breaks intervals: Define your own durations for each cycle.
8+
- Pause whenever you want: Pause the timer when you want to take a break.
9+
- Cycles: Run Multiple cycles of work and break intervals
10+
- Console output: Show work and break intervals in the console.
11+
12+
## How it works
13+
14+
The Pomodoro Timer follow these steps:
15+
1. Set your work and break intervals.
16+
2. Take a short break every work interval.
17+
3. After a set number of cycles, take a long break.
18+
19+
## Usage
20+
21+
1. Clone this repository to your machine.
22+
2. Run the Python script from the command line.
23+
'''python pomodoro_timer.py'''
24+
25+
## Author
26+
27+
[MeuHubPython](https://github.com/MeuHubPython)
28+

Pomodoro Timer/main.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import time
2+
3+
4+
def countdown(minutes, label):
5+
total_seconds = minutes * 60
6+
while total_seconds:
7+
mins, secs = divmod(total_seconds, 60)
8+
timer = f"{mins:02d}:{secs:02d}"
9+
print(f"{label} Timer: {timer}", end="\r")
10+
time.sleep(1)
11+
total_seconds -= 1
12+
print(f"\n{label} finished!")
13+
14+
15+
def handle_pause_stop():
16+
while True:
17+
user_input = input(
18+
"\nPress 'p' to pause, 's' to stop, or 'Enter' to continue: "
19+
).lower()
20+
if user_input == "p":
21+
print("Timer paused. Press 'Enter' to resume.")
22+
input()
23+
elif user_input == "s":
24+
print("Timer stopped.")
25+
return True # Return True to signal that the timer should stop
26+
else:
27+
return False # Return False to continue with the timer
28+
29+
30+
def pomodoro_timer(work_min, short_break_min, long_break_min, cycles):
31+
for i in range(cycles):
32+
print(f"\nCycle {i+1} of {cycles}")
33+
countdown(work_min, "Work")
34+
if i < cycles - 1:
35+
print("\nStarting short break...")
36+
if handle_pause_stop():
37+
return
38+
countdown(short_break_min, "Short Break")
39+
else:
40+
print("\nStarting long break...")
41+
if handle_pause_stop():
42+
return
43+
countdown(long_break_min, "Long Break")
44+
if not repeat_or_end():
45+
return
46+
47+
48+
def repeat_or_end():
49+
user_input = input(
50+
"\nCycle finished. Would you like to repeat the cycle? (y/n): "
51+
).lower()
52+
return user_input == "y"
53+
54+
55+
def get_valid_input(prompt):
56+
while True:
57+
try:
58+
value = int(input(prompt))
59+
if value <= 0:
60+
raise ValueError
61+
return value
62+
except ValueError:
63+
print("Invalid input. Please enter a positive integer.")
64+
65+
66+
if __name__ == "__main__":
67+
work_minutes = get_valid_input("Enter work interval in minutes: ")
68+
short_break_minutes = get_valid_input("Enter short break interval in minutes: ")
69+
long_break_minutes = get_valid_input("Enter long break interval in minutes: ")
70+
cycles = get_valid_input("Enter the number of cycles: ")
71+
72+
pomodoro_timer(work_minutes, short_break_minutes, long_break_minutes, cycles)

Pomodoro Timer/runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Python 3.10.12

0 commit comments

Comments
 (0)