import time
import pyautogui
# Set the Pomodoro timer duration in minutes (e.g., 25)
pomodoro_duration = 25
# Set the short break duration in minutes (e.g., 5)
short_break_duration = 5
# Set the long break duration in minutes (e.g., 15)
long_break_duration = 15
# Set the number of Pomodoro cycles to complete (e.g., 4)
num_pomodoro_cycles = 4
# Set the number of short breaks to take during a Pomodoro cycle (e.g., 3)
num_short_breaks = 3
# Set the number of long breaks to take during a Pomodoro cycle (e.g., 1)
num_long_breaks = 1
# Set the total number of Pomodoro cycles (e.g., 100)
total_cycles = 100
# Initialize the current cycle number
current_cycle_number = 1
# Initialize the current cycle type (Pomodoro, Short Break, or Long Break)
current_cycle_type = "Pomodoro"
# Set the start time for the Pomodoro session
start_time = time.time()
# Start the timer for the Pomodoro session
while current_cycle_number <= total_cycles:
if current_cycle_type == "Pomodoro":
print(f"Starting a {current_cycle_number} minute {current_cycle_type}...")
# Set the working time using pyautogui
pyautogui.hotkey('ctrl', 's')
# Set the working time duration
time_elapsed = time.time() - start_time
remaining_time = pomodoro_duration - time_elapsed
working_time = remaining_time
if working_time < 0:
working_time = 0
# Pause the timer
time.sleep(working_time * 60)
# Switch to a short break
current_cycle_type = "Short Break"
print(f"End of {current_cycle_number} minute {current_cycle_type}.")
# Set the break time using pyautogui
pyautogui.hotkey('ctrl', 'b')
# Set the break time duration
time_elapsed = time.time() - start_time
break_time = long_break_duration - time_elapsed
if break_time < 0:
break_time = 0
# Resume the timer
time.sleep(break_time * 60)
# Switch to a long break
current_cycle_type = "Long Break"
print(f"End of {current_cycle_number} minute {current_cycle_type}.")
# Set the break time using pyautogui
pyautogui.hotkey('ctrl', '9')
# Set the break time duration
time_elapsed = time.time() - start_time
break_time = short_break_duration - time_elapsed
if break_time < 0:
break_time = 0
# Resume the timer
time.sleep(break_time * 60)
# Increase the cycle number and switch to the next cycle type
current_cycle_number += 1
if current_cycle_number <= num_pomodoro_cycles:
current_cycle_type = "Pomodoro"
else:
current_cycle_type = "Done"
else:
print(f"End of {current_cycle_number} minute {current_cycle_type}.")
break
print("Session completed.")
This code sets up a Pomodoro timer application using the pyautogui library in Python. It allows the user to customize the duration of the Pomodoro, short break, and long break, as well as the number of cycles to complete. The timer works by alternating between working sessions, short breaks, and long breaks based on the user's settings. Once the specified number of Pomodoro cycles is completed, the application outputs "Session completed."