Skip to content
Open
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions Pomodoro_Timer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)

# Pomodoro Timer

## 🛠️ Description

A simple command-line Pomodoro timer to help you stay focused. It follows the Pomodoro Technique — work for 25 minutes, take a 5 minute break, and after every 4 sessions take a longer 15 minute break. All times are customizable.

## ⚙️ Languages or Frameworks Used

You only need Python 3 to run this script. No extra libraries needed — it uses only built-in modules (`time`, `os`, `sys`).

You can visit [here](https://www.python.org/downloads/) to download Python.

## 🌟 How to run

Start with default settings (25 min work / 5 min break / 15 min long break / 4 sessions):

```sh
python pomodoro.py
```

Use custom times (all values in minutes):

```sh
python pomodoro.py 25 5 15 4
```

```
Arguments: [work_time] [short_break] [long_break] [number_of_sessions]
```

Stop anytime with `Ctrl + C`.

## 📺 Demo

```
==============================
POMODORO TIMER
==============================

Work: 25 min
Short break: 5 min
Long break: 15 min
Sessions: 4

Press Enter to start session 1/4...

Session 1/4 - WORK
==============================
Time left: 24:37
```

## 🤖 Author

[Kaligotla Sri Datta Sai Vithal](https://github.com/Sridattasai18)
125 changes: 125 additions & 0 deletions Pomodoro_Timer/pomodoro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import time # for countdown
import sys # for command line arguments
import os # for clearing the screen

# default timer settings (in minutes)
WORK_TIME = 25
SHORT_BREAK = 5
LONG_BREAK = 15
SESSIONS_BEFORE_LONG_BREAK = 4


def clear_screen():
"""clear the terminal screen"""
# "cls" on windows, "clear" on mac/linux
os.system("cls" if os.name == "nt" else "clear")


def format_time(seconds):
"""turn seconds into MM:SS format"""
mins = seconds // 60
secs = seconds % 60
return str(mins).zfill(2) + ":" + str(secs).zfill(2)


def countdown(minutes, label):
"""run a countdown timer and show it in the terminal"""
total_seconds = minutes * 60

print("\n" + label)
print("=" * 30)

while total_seconds > 0:
# show the time remaining
print("\r Time left: " + format_time(total_seconds), end="", flush=True)
time.sleep(1)
total_seconds -= 1

# timer finished
print("\r Time left: 00:00")
print("\nDone!")

# make a beep sound to alert the user
# \a is the bell character, works on most terminals
print("\a")


def run_pomodoro(work, short_brk, long_brk, total_rounds):
"""run the full pomodoro cycle"""

clear_screen()
print("=" * 30)
print(" POMODORO TIMER")
print("=" * 30)
print("")
print(" Work: " + str(work) + " min")
print(" Short break: " + str(short_brk) + " min")
print(" Long break: " + str(long_brk) + " min")
print(" Sessions: " + str(total_rounds))
print("")

session = 1

while session <= total_rounds:
# work session
input("Press Enter to start session " + str(session) + "/" + str(total_rounds) + "...")
clear_screen()
countdown(work, "Session " + str(session) + "/" + str(total_rounds) + " - WORK")

# check if we're done
if session == total_rounds:
break

# decide which break to take
if session % SESSIONS_BEFORE_LONG_BREAK == 0:
# every 4th session, take a long break
input("\nPress Enter to start long break...")
clear_screen()
countdown(long_brk, "LONG BREAK - relax!")
else:
# normal short break
input("\nPress Enter to start short break...")
clear_screen()
countdown(short_brk, "SHORT BREAK - stretch!")

session += 1

# all sessions done
print("\n" + "=" * 30)
print(" All " + str(total_rounds) + " sessions complete!")
print(" Great work today!")
print("=" * 30)


# --- main program starts here ---

if __name__ == "__main__":

# let the user customize times from command line
# usage: python pomodoro.py [work] [short_break] [long_break] [sessions]
if len(sys.argv) > 1 and sys.argv[1] == "--help":
print("Pomodoro Timer")
print("")
print("Usage:")
print(" python pomodoro.py # default (25/5/15, 4 sessions)")
print(" python pomodoro.py 25 5 15 4 # custom times and sessions")
print(" python pomodoro.py [work] [short] [long] [sessions]")
print("")
print("Arguments (all in minutes):")
print(" work - work session length (default: 25)")
print(" short - short break length (default: 5)")
print(" long - long break length (default: 15)")
print(" sessions - number of work sessions (default: 4)")

else:
# read custom values or use defaults
work = int(sys.argv[1]) if len(sys.argv) > 1 else WORK_TIME
short_brk = int(sys.argv[2]) if len(sys.argv) > 2 else SHORT_BREAK
long_brk = int(sys.argv[3]) if len(sys.argv) > 3 else LONG_BREAK
rounds = int(sys.argv[4]) if len(sys.argv) > 4 else SESSIONS_BEFORE_LONG_BREAK

try:
run_pomodoro(work, short_brk, long_brk, rounds)
except KeyboardInterrupt:
# user pressed Ctrl+C to stop early
print("\n\nTimer stopped. See you next time!")