-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path202020-rule-reminder.py
83 lines (67 loc) · 3.02 KB
/
202020-rule-reminder.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
76
77
78
79
80
81
82
83
from datetime import datetime, timedelta # for accessing the datetime functions
import time
import os # for getting terminal features functions
from plyer import notification # for acessing notification function of the library
import winsound # for accessing sounds
def exit_script(): # function for exiting the script,
print("- Exiting ...")
time.sleep(1)
os.system('cls' if os.name == 'nt' else 'clear')
print('- Script disabled')
time.sleep(1)
exit()
def decision_continue():
while True:
decision = str(input("- Continue (yes or no [abort]): "))
if decision == "yes" or decision == "y":
main()
break
elif decision == "no" or decision == "n":
exit_script()
break
else:
os.system('cls' if os.name == 'nt' else 'clear')
print("- Invalid input, only enter inputs 'yes' or 'no'")
def notify(): # funtion for the body of the notification
computer_name = os.environ.get("COMPUTERNAME", "User") # COMPUTERNAME = user's computer name, else User if not found
duration = 1500
freq = 440
winsound.Beep(freq, duration)
time.sleep(1)
notification.notify(
title = f"Time to Rest your Eyes, {computer_name}!",
message = "20 minutes is up! Make sure to look 20ft (~6 meters) away outside for 20 seconds.",
timeout = 1
)
def timer_tillNotify(): # function for the timer comparison
n = 20 # assinged int minutes for timer to add to the initiated_time
initiated_time = datetime.now()
while True:
current_time = datetime.now()
final_time = initiated_time + timedelta(minutes=n)
# initiated_time is when the timer stamps the current time and is fixed, current_time changes for user feedback,
# final_time is the calculated time when the timer will alarm
os.system('cls' if os.name == 'nt' else 'clear')
# the time format for printing
current_time_str = current_time.strftime("%H:%M:%S")
final_time_str = final_time.strftime("%H:%M:%S")
print(f"- {current_time_str}/ {final_time_str}") # printing the time
if current_time >= final_time: # when the time reaches 20 minutes or more, this if-else will work
print("- Notifying ...")
time.sleep(1)
notify()
os.system('cls' if os.name == 'nt' else 'clear')
decision_continue()
time.sleep(1) # adding a second to replicate a second in time
def main():
os.system('cls' if os.name == 'nt' else 'clear') # clearing the terminal for a cleaner look
exit_key_words = ["quit", "exit", "0"]
startTimer = str(input("- Please enter any key to start the 20-20-20 Rule (to exit, enter: '0'): "))
if startTimer in exit_key_words:
exit_script()
else:
print("- Starting, please wait ...")
time.sleep(1)
timer_tillNotify()
if __name__ == "__main__":
main()