Skip to content

Commit c3d2c6e

Browse files
authored
PR #21: Pomodoro-Timer
Pomodoro timer Merge pull request #21 from adedayoprcs/pomodoro-timer
2 parents d8c5650 + 09ce106 commit c3d2c6e

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Pomodoro-Timer/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Pomodoro Timer
2+
This Python script provides a simple Pomodoro timer to help you manage your work or study sessions effectively. The Pomodoro Technique is a time management method that encourages focused work periods followed by short breaks. This script allows you to specify a task and the duration of your work session in hours, minutes, and seconds.
3+
4+
How to Use
5+
Run the script in a Python environment.
6+
7+
You will be prompted to enter the task you want to work on.
8+
9+
Next, enter the duration of your work session in hours, minutes, and seconds.
10+
11+
The timer will start, and you'll see the time remaining for your work session.
12+
13+
During the work session, you'll receive a short break (5 minutes) after every 25 minutes of work. After four work sessions, you'll get a longer break (20 minutes).
14+
15+
Once the timer runs out, you'll be prompted to enter a new task and duration to continue working.
16+
17+
To exit the script, simply close the terminal or interrupt it using Ctrl+C.

Pomodoro-Timer/pomodoro.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import time
2+
import datetime
3+
4+
# Create a function that acts as a countdown
5+
def pomodoro_timer(task, h, m, s):
6+
# Calculate the total number of seconds
7+
total_seconds = h * 3600 + m * 60 + s
8+
9+
# Counter to keep track of the breaks
10+
break_count = 0
11+
12+
while total_seconds > 0:
13+
# Timer represents time left on the countdown
14+
timer = datetime.timedelta(seconds=total_seconds)
15+
# Prints the time left on the timer
16+
print(f"Focusing on {task}... Session time left: {timer}", end="\r")
17+
18+
# Delays the program one second
19+
time.sleep(1)
20+
21+
# Reduces total time by one second
22+
total_seconds -= 1
23+
24+
# Check if it's time for a break (only for the first 4 breaks)
25+
if total_seconds > 0 and break_count < 4 and total_seconds % 1500 == 0:
26+
print("\nNow on a short break!")
27+
time.sleep(300) # Short break for 5 minutes
28+
break_count += 1
29+
30+
# Check if it's time for a long break (after 4 sessions)
31+
elif total_seconds > 0 and break_count == 4 and total_seconds % 1500 == 0:
32+
print("\nNow on a long break!")
33+
time.sleep(1200) # Long break for 20 minutes
34+
break_count = 0 # Reset the break count for the next cycle
35+
36+
print("\nTask Completed")
37+
38+
# Inputs for hours, minutes, and seconds on the timer
39+
task = input("Enter the task to focus on: ")
40+
h = int(input("Enter the time in hours: "))
41+
m = int(input("Enter the time in minutes: "))
42+
s = int(input("Enter the time in seconds: "))
43+
pomodoro_timer(task, h, m, s)

0 commit comments

Comments
 (0)