Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions Pomodoro-Timer/pomodoro.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@
import datetime

# Create a function that acts as a countdown
def pomodoro_timer(task, h, m, s):
# Calculate the total number of seconds
total_seconds = h * 3600 + m * 60 + s

def pomodoro_timer(task, total_seconds):
# Counter to keep track of the breaks
break_count = 0

while total_seconds > 0:
# Timer represents time left on the countdown
timer = datetime.timedelta(seconds=total_seconds)
# Prints the time left on the timer
print(f"Focusing on {task}... Session time left: {timer}", end="\r")

# Delays the program one second
# Delay the program one second
time.sleep(1)

# Reduces total time by one second
total_seconds -= 1

# Check if it's time for a break (only for the first 4 breaks)
# Check if it's time for a break (only for the first 4 breaks)
if total_seconds > 0 and break_count < 4 and total_seconds % 1500 == 0:
print("\nNow on a short break!")
time.sleep(300) # Short break for 5 minutes
time.sleep(300) # 5-minute short break
break_count += 1

# Check if it's time for a long break (after 4 sessions)
Expand All @@ -35,9 +30,11 @@ def pomodoro_timer(task, h, m, s):

print("\nTask Completed")

# Inputs for hours, minutes, and seconds on the timer
# Get user input (In HH:MM:SS format)
task = input("Enter the task to focus on: ")
h = int(input("Enter the time in hours: "))
m = int(input("Enter the time in minutes: "))
s = int(input("Enter the time in seconds: "))
pomodoro_timer(task, h, m, s)
time_input = input("Enter time in HH:MM:SS format (e.g., 00:25:00 for 25 min): ")

# Convert input time to seconds
h, m, s = map(int, time_input.split(":"))
total_seconds = h * 3600 + m * 60 + s
pomodoro_timer(task, total_seconds)