Skip to content

Commit 3839fa0

Browse files
author
Glenn
committed
PCC52 glenncalleja
1 parent 20e051e commit 3839fa0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

52/glenncalleja/PomodoroTimer.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from datetime import datetime, timedelta
2+
from time import sleep
3+
import os
4+
5+
6+
def cls():
7+
os.system('cls' if os.name == 'nt' else 'clear')
8+
9+
10+
def timer(duration: timedelta, state_name: str,
11+
start_time: datetime = None):
12+
if start_time is None:
13+
start_time = datetime.now()
14+
while (datetime.now() < start_time + duration):
15+
cls()
16+
now = datetime.now()
17+
print(f"In {state_name}..")
18+
print(f"Current Time is {now}")
19+
print(f"{state_name} ends at {start_time + duration}")
20+
print(f"Time left: {start_time + duration - now}")
21+
print("^C to quit")
22+
sleep(1)
23+
24+
25+
def start_pomodoro(pomodoro_delta: timedelta, break_delta: timedelta):
26+
in_pomodoro_state = True
27+
while 1:
28+
if in_pomodoro_state:
29+
timer(duration=pomodoro_delta, state_name="Pomodoro")
30+
else:
31+
timer(duration=break_delta, state_name="Break")
32+
in_pomodoro_state = not(in_pomodoro_state)
33+
34+
35+
pomodoro_minutes = int(input("Enter your Pomodoro Time in minutes: "))
36+
pomodoro_timedelta = timedelta(minutes=pomodoro_minutes)
37+
38+
break_minutes = int(input("Enter your Break Time in minutes: "))
39+
break_timedelta = timedelta(minutes=break_minutes)
40+
41+
start_pomodoro(pomodoro_timedelta, break_timedelta)

0 commit comments

Comments
 (0)