-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpomodoro.py
More file actions
114 lines (92 loc) · 2.88 KB
/
pomodoro.py
File metadata and controls
114 lines (92 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import time
import csv
import argparse
from datetime import datetime
from pathlib import Path
LOG_FILE = Path("pomodoro_log.csv")
# ---------------- Logging ----------------
def log_session(session_type, duration):
file_exists = LOG_FILE.exists()
with open(LOG_FILE, "a", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
if not file_exists:
writer.writerow(["timestamp", "session_type", "duration_minutes"])
writer.writerow([
datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
session_type,
duration
])
# ---------------- Timer ----------------
def countdown(minutes, label):
seconds = minutes * 60
print(f"\n⏱️ {label} — {minutes} min")
while seconds > 0:
mins, secs = divmod(seconds, 60)
print(f"{mins:02d}:{secs:02d}", end="\r")
time.sleep(1)
seconds -= 1
print(f"\n✅ {label} finished")
# ---------------- Core Logic ----------------
def run_pomodoro(args):
focus_count = 0
print("\n🍅 Pomodoro CLI started")
print("Press CTRL+C to stop\n")
try:
while True:
# Focus
countdown(args.focus, "Focus")
log_session("Focus", args.focus)
focus_count += 1
# Break logic
if focus_count % args.cycles == 0:
countdown(args.long_break, "Long Break")
log_session("Long Break", args.long_break)
else:
countdown(args.short_break, "Short Break")
log_session("Short Break", args.short_break)
except KeyboardInterrupt:
print("\n🛑 Pomodoro stopped")
print(f"📂 Sessions saved to {LOG_FILE.resolve()}")
# ---------------- CLI ----------------
def parse_args():
parser = argparse.ArgumentParser(
description="🍅 Pomodoro Timer CLI"
)
parser.add_argument(
"--focus",
type=int,
default=25,
help="Focus duration in minutes (default: 25)"
)
parser.add_argument(
"--short-break",
type=int,
default=5,
help="Short break duration in minutes (default: 5)"
)
parser.add_argument(
"--long-break",
type=int,
default=15,
help="Long break duration in minutes (default: 15)"
)
parser.add_argument(
"--cycles",
type=int,
default=4,
help="Number of focus sessions before a long break (default: 4)"
)
return parser.parse_args()
# ---------------- Entry ----------------
if __name__ == "__main__":
args = parse_args()
run_pomodoro(args)
#Some examples for commands to run in CMD
# # Classic Pomodoro
#python pomodoro.py
# Deep focus mode
#python pomodoro.py --focus 50 --short-break 10
# Custom cycles
#python pomodoro.py --cycles 3
#another custom
#python pomodoro.py --focus 50 --short-break 10 --long-break 20 --cycles 4