-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathHealthy_Programmer_Harry_solution.py
49 lines (39 loc) · 1.4 KB
/
Healthy_Programmer_Harry_solution.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
# Exercise 7: Healthy Programmer by Harry
from pygame import mixer
from datetime import datetime
from time import time
def music_on_loop(file, stopper):
mixer.init()
mixer.music.load(file)
mixer.music.play()
while True:
a = input()
if a == stopper:
mixer.music.stop()
break
def log_now(msg):
with open("mylog.txt", "a") as f:
f.write(f"{msg} {datetime.now()}\n")
if __name__ == "__main__":
init_water = time()
init_eyes = time()
init_exercise = time()
water_interval = 5
eyes_interval = 10
exercise_interval = 20
while True:
if time() - init_water > water_interval:
print("Water Drinking time. Enter 'drank' to stop the alarm. !!!")
music_on_loop("alarm.mp3", "drank")
init_water = time()
log_now("Drank water at")
if time() - init_eyes > eyes_interval:
print("Eye Relax time. Enter 'eydone' to stop the alarm. !!!")
music_on_loop("alarm.mp3", "eydone")
init_eyes = time()
log_now("Eye Relaxed at")
if time() - init_exercise > exercise_interval:
print("Physical Activity time. Enter 'exdone' to stop the alarm. !!!")
music_on_loop("alarm.mp3", "exdone")
init_exercise = time()
log_now("Physical Exercise at")