forked from arvimal/100DaysofCode-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpomodoro-2.py
More file actions
58 lines (43 loc) · 1.52 KB
/
pomodoro-2.py
File metadata and controls
58 lines (43 loc) · 1.52 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
#!/usr/bin/env python3
# Pybites #100DaysofChallenge third day Challenge
# Create a Pomodoro application
import datetime
import sys
pomodoro_count = 0
def set_pomodoro():
"""
Set a pomodoro
"""
print("\n{:^50}".format("- Pomodoro Timer -"))
# 1. Counter to note the pomodoros
# Global var set, so as to not be cleared while being updated.
global pomodoro_count
# 2. Safety checks
value = input("\nEnter your time in minutes: ")
if value == "quit".lower():
sys.exit("\nExiting the Pomodoro tracker.\n")
elif value == "":
set_pomodoro()
elif value.isdecimal():
try:
value = int(value)
except [ValueError]:
set_pomodoro()
# 3. Setting the current time
time_now = datetime.datetime.now()
print("\n* Current time: {}".format(time_now))
# 4. Setting the timedelta, ie. the time in future
set_time = datetime.timedelta(minutes=value)
# 5. Finding the difference between the current time and future time
delta = time_now + set_time
print("* Finishing at: {}\n".format(delta))
# 6. Waiting till the current time reaches the future time
# We finish the set pomodoro if current time equals to future time.
while True:
if delta == datetime.datetime.now():
print("Time up! {} minutes completed!".format(value))
pomodoro_count += 1
print("\nPomodoros completed: {}".format(pomodoro_count))
set_pomodoro()
if __name__ == "__main__":
set_pomodoro()