-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
132 lines (99 loc) · 3.98 KB
/
timer.py
File metadata and controls
132 lines (99 loc) · 3.98 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import sys
import time as t
from pygame import mixer
mixer.init()
BASE_DIR = (
os.path.dirname(sys.executable)
if getattr(sys, "frozen", False)
else os.path.dirname(os.path.abspath(__file__))
)
symbols = {
"0": [" ", " @ @ @ ", " @ @ ", " @ @ ", " @ @ ", " @ @ @ ", " "],
"1": [" ", " @@ ", " @ @ ", " @ ", " @ ", " @ ", " "],
"2": [" ", " @ @ @ ", " @ ", " @ @ @ ", " @ ", " @ @ @ ", " "],
"3": [" ", " @ @ @ ", " @ ", " @ @ @ ", " @ ", " @ @ @ ", " "],
"4": [" ", " @ @ ", " @ @ ", " @ @ @ ", " @ ", " @ ", " "],
"5": [" ", " @ @ @ ", " @ ", " @ @ @ ", " @ ", " @ @ @ ", " "],
"6": [" ", " @ @ @ ", " @ ", " @ @ @ ", " @ @ ", " @ @ @ ", " "],
"7": [" ", " @ @ @ ", " @ ", " @ ", " @ ", " @ ", " "],
"8": [" ", " @ @ @ ", " @ @ ", " @ @ @ ", " @ @ ", " @ @ @ ", " "],
"9": [" ", " @ @ @ ", " @ @ ", " @ @ @ ", " @ ", " @ @ @ ", " "],
":": [" ", " ", " @ ", " ", " @ ", " ", " "],
}
def play_alarm():
mixer.music.load(os.path.join(BASE_DIR, "media", "timeout.mp3"))
mixer.music.play()
def play_ticking():
mixer.music.load(os.path.join(BASE_DIR, "media", "ticking.mp3"))
mixer.music.play(loops=-1)
def print_time(time):
print("\n\033[92m")
for i in range(7):
print("\n", end="")
for j in time:
print(symbols[j][i], end=" ")
print("\n\n\033[0m")
def is_correctformat(lst: list):
if len(lst) == 3 and all([i.strip().isdigit() for i in lst]):
return True
return False
def timer():
os.system("cls")
msg = ""
while True:
os.system("cls")
print(
"\n\n\n\033[93mEnter the time in format : HH.MM.SS | 'q' to quit\n\n\033[0m"
)
print(msg)
msg=""
T = "0:0:0".split(":")
time = input("\n\033[96m>>> \033[0m").strip()
if time.lower() == "q":
msg = "\n\033[34mThanks for using the Timer\n"
break
time = time.split(".")
if not is_correctformat(time):
msg = "\033[31mError: Invalid time format\033[0m"
continue
while True:
play_ticking()
try:
for i in range(
int(time[0]) * 60 * 60 + int(time[1]) * 60 + int(time[2]), -1, -1
):
os.system("cls")
tm = f"{i // 3600}:{(i % 3600) // 60}:{(i % 3600) % 60}"
print_time(tm)
print("\n\n\033[93mPress Ctrl+C to stop the timer\033[0m\n")
T = tm.split(":")
t.sleep(0.9999)
print("\n\033[31mTIME IS UP !!!")
mixer.music.stop()
play_alarm()
input(
"\n\033[33mThe alarm will automaticlly be stoped in 30 seconds.\n\n\033[0mPress \033[93mEnter\033[0m to Reset..."
)
mixer.music.stop()
break
except KeyboardInterrupt:
mixer.music.stop()
time = T
resume = False
while True:
os.system("cls")
print_time(":".join(time))
print(
"\033[93mTimer Paused\033[0m\n\n'r' : to Resume the timer\n'q' : to reset the timer\n\n"
)
i = input("\033[96m>>> \033[0m").strip()
if i.lower() == "r":
resume = True
break
if i.lower() == "q":
break
if not resume:
break
if __name__ == "__main__":
timer()