-
Notifications
You must be signed in to change notification settings - Fork 0
/
kill_the_myopia.py
75 lines (68 loc) · 1.82 KB
/
kill_the_myopia.py
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
import time
import os
import subprocess
import multiprocessing
from playsound import playsound
def sendmessage(message):
subprocess.Popen(['notify-send', "Kill The Myopia",message])
return
def main():
nbLap = 0
while True:
noPause()
pause()
nbLap += 1
if nbLap == 1:
print("You took", nbLap, "break")
else:
print("You took", nbLap, "breaks")
def noPause():
t = 1200 #1200 secondes -> 20 minutes
while t:
min, sec = divmod(t, 60)
printformat = '{:02d}:{:02d}'.format(min, sec)
print(printformat, end='\r')
time.sleep(1)
t -= 1
if os.path.exists('./soundalarm.mp3'):
p = multiprocessing.Process(target=playsound, args=("soundalarm.mp3",))
p.start()
input("press ENTER to continue")
p.terminate()
p.kill()
else:
print('\007')
input("press ENTER to continue")
print("-----")
print("Break time")
print("-----")
sendmessage("Break time")
def pause():
pauseTime = 300 #300 secondes -> 5 minutes
while pauseTime:
min, sec = divmod(pauseTime, 60)
printformat = '{:02d}:{:02d}'.format(min, sec)
print(printformat, end='\r')
time.sleep(1)
pauseTime -= 1
if os.path.exists('./soundalarm.mp3'):
p = multiprocessing.Process(target=playsound, args=("soundalarm.mp3",))
p.start()
input("press ENTER to continue")
p.terminate()
p.kill()
else:
print('\007')
input("press ENTER to continue")
print("-----")
print("Screen time")
print("-----")
sendmessage("Screen time")
if __name__ == "__main__":
print("Welcome to Kill The Myopia !")
try:
main()
except KeyboardInterrupt:
print('')
print('Thanks for using Kill The Myopia ! See you soon :)')
os._exit(0)