-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification_manager.py
52 lines (41 loc) · 1.59 KB
/
notification_manager.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
from twilio.rest import Client
TWILIO_SID = "YOUR TWILIO STRING IDENTIFIRE"
TWILIO_AUTH_TOKEN = "YOUT TWILIO AUTHENTICATION CODE "
TWILIO_VIRTUAL_NUMBER = "YOUR TWILIO VIRTUAL NUMBER"
TWILIO_VERIFIED_NUMBER = "YOUR TWILIO VERIFICATION NUMBER"
class NotificationManager:
def __init__(self):
self.client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)
def send_sms(self, message):
message = self.client.messages.create(
body=message,
from_=TWILIO_VIRTUAL_NUMBER,
to=TWILIO_VERIFIED_NUMBER,
)
# Prints if successfully sent.
print(message.sid)
import smtplib
from twilio.rest import Client
MAIL_PROVIDER_SMTP_ADDRESS = "smtp.gmail.com"
MY_EMAIL = "YOUR EMAIL ID HERE"
MY_PASSWORD = "YOUR EMAIL PASSWORD HERE"
class NotificationManager:
def __init__(self):
self.client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)
def send_sms(self, message):
message = self.client.messages.create(
body=message,
from_=TWILIO_VIRTUAL_NUMBER,
to=TWILIO_VERIFIED_NUMBER,
)
print(message.sid)
def send_emails(self, emails, message, google_flight_link):
with smtplib.SMTP(MAIL_PROVIDER_SMTP_ADDRESS) as connection:
connection.starttls()
connection.login(MY_EMAIL, MY_PASSWORD)
for email in emails:
connection.sendmail(
from_addr=MY_EMAIL,
to_addrs="RECEIVER EMAIL ID",
msg=f"Subject:New Low Price Flight!\n\n{message}\n{google_flight_link}".encode('utf-8')
)