-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReminderBot.py
53 lines (39 loc) · 1.36 KB
/
ReminderBot.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
import json
import datetime as dt
import time
from plyer import notification
with open("schedule.json") as s:
data = json.load(s)
# current day in string
current_day = dt.datetime.today().strftime("%A")
# takes string time and converts to time object
def time_convert(t):
t = t + ":00"
return dt.datetime.strptime(t, "%X").time()
# finds time remaining until a specified time (t)
def wait_time(t):
current_time = dt.datetime.now().time()
target_time = time_convert(t)
td1 = dt.timedelta(hours=current_time.hour, minutes=current_time.minute, seconds=current_time.second)
td2 = dt.timedelta(hours=target_time.hour, minutes=target_time.minute, seconds=target_time.second)
return (td2 - td1).total_seconds() - 300.00
def send_notification(message):
notification.notify(
title='Online Classes',
message=message,
app_icon=None,
timeout=10, # seconds
)
for a, b in data[current_day].items():
wait = wait_time(a)
if wait < 0.00:
continue
else:
text1 = f"{b} begins in 5 minutes at {a}."
text2 = f"{b} has started."
print("alarm at: " + a, end=", ")
print("time to wait in seconds: " + str(wait))
time.sleep(wait)
send_notification(text1)
time.sleep(300)
send_notification(text2)