-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.py
59 lines (47 loc) · 1.69 KB
/
notify.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
from twilio.rest import Client
import os
from dotenv import load_dotenv
load_dotenv(".env")
class Notify():
def __init__(self, kernel_name, notify_message = None, tone_path = None):
self.account_sid = os.environ.get("account_sid")
self.auth_token = os.environ.get("auth_token")
self.twillio_number = os.environ.get("number")
self.personal_number = os.environ.get("personal_number")
self.kernel_name = kernel_name
self.notify_message = notify_message
self.tone_path = tone_path
def notifyMessage(self):
client = Client(self.account_sid, self.auth_token)
print("sending message")
try:
message = client.messages \
.create(
body = self.kernel_name + " " + self.notify_message,
from_= self.twillio_number,
to = self.personal_number
)
except:
print("Error occured while sending twillio message")
return
print("sms sent successfully with id "+message.sid)
def notifyDesktop(self):
print("notifying desktop")
if(os.name == "posix"):
print("linux notti ", self.kernel_name, self.notify_message)
os.popen("notify-send " + str(self.kernel_name) + " " + str(self.notify_message))
elif(os.name == "nt"):
try:
from win10toast import ToastNotifier
except:
print("win10toast need to be installed for windows notifications")
return
toaster = ToastNotifier()
toaster.show_toast("{}".format(self.kernel_name),"{}".format(self.notify_message))
else:
print("Only linux and windows notifications are supported")
def notifyTone(self):
print(self.tone_path)
os.system("ffplay " + self.tone_path + " -nodisp")
#to='+917020846176'
#to='+919423514849'