Skip to content

Commit 549d9cc

Browse files
authored
Merge pull request #782 from lauramariel/community
day 3 challenge
2 parents 464d542 + 14896a8 commit 549d9cc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

52/lauramariel/pomodoro.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import time
2+
from datetime import datetime
3+
from datetime import timedelta
4+
5+
def timer(timer_type):
6+
if timer_type == "pomodoro":
7+
endtime = datetime.now() + timedelta(minutes=25)
8+
elif timer_type == "short_break":
9+
endtime = datetime.now() + timedelta(minutes=5)
10+
elif timer_type == "long_break":
11+
endtime = datetime.now() + timedelta(minutes=10)
12+
13+
while (datetime.now().replace(microsecond=0) != endtime.replace(microsecond=0)):
14+
timeleft = endtime - datetime.now()
15+
timeleft = str(timeleft).split(".")[0]
16+
print(f"{timeleft}", end='\r')
17+
time.sleep(1)
18+
19+
print(f"{timer_type} done!")
20+
return True
21+
22+
def main():
23+
pomodoro_count = 0
24+
while True:
25+
intervals = ["pomodoro", "break"]
26+
27+
for timer_type in intervals:
28+
29+
if timer_type == "pomodoro":
30+
pomodoro_count += 1
31+
print(f"It's work time! Pomodoro #{pomodoro_count}")
32+
33+
if timer_type == "break":
34+
# determine whether it's a short or long break
35+
if pomodoro_count < 4:
36+
# it's a short break
37+
timer_type = "short_break"
38+
else:
39+
timer_type = "long_break"
40+
pomodoro_count = 0
41+
print(f"Starting {timer_type}!")
42+
43+
timer(timer_type=timer_type)
44+
45+
if __name__ == "__main__":
46+
main()

0 commit comments

Comments
 (0)