Skip to content

Commit d05699c

Browse files
committed
day 3 pomodoro timer
1 parent 0820b2c commit d05699c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

days/01-03-datetimes/code/pomodoro.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from datetime import datetime, timedelta
2+
import time
3+
4+
POMODORO_INTERVAL = 25
5+
6+
7+
def main():
8+
start_time = datetime.now()
9+
print(f"Starting timer at {start_time}")
10+
print()
11+
pomodoro_count(start_time)
12+
return
13+
14+
15+
def pomodoro_count(start):
16+
duration = timedelta(minutes=POMODORO_INTERVAL)
17+
18+
for t in range(duration.seconds + 1):
19+
current_increment = start + timedelta(seconds=1)
20+
print("\r", f"Elapsed time: {format_counter(t)} m:s", end="")
21+
# print(f"Elapsed time: {t} seconds")
22+
time.sleep(1)
23+
24+
print()
25+
print(f"Stopping timer at {datetime.now()}")
26+
27+
28+
def format_counter(seconds):
29+
return f"{int(seconds/60)}:{int(seconds % 60)}"
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)