-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification_manager.py
37 lines (31 loc) · 1.09 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
from twilio.rest import Client
import os
from dotenv import load_dotenv
import smtplib
load_dotenv()
account_sid = os.getenv('TWILIO_ACCOUNT_SID')
auth_token = os.getenv('TWILIO_AUTH_TOKEN')
my_number=os.getenv("PHONE")
twilio_number=os.getenv("TWILIO_PHONE")
mail = os.getenv("CORREO")
password = os.getenv("PASSWORD")
class NotificationManager:
def __init__(self):
self.client = Client(account_sid,auth_token)
def send_sms(self, message):
message = self.client.messages.create(
body=message,
from_=twilio_number,
to=my_number,
)
print(message.sid)
def send_emails(self, emails, message, google_flight_link):
with smtplib.SMTP("smtp.office365.com:587") as connection:
connection.starttls()
connection.login(mail,password)
for email in emails:
connection.sendmail(
from_addr=mail,
to_addrs=email,
msg=f"Subject:New Low Price Flight!\n\n{message}\n{google_flight_link}".encode('utf-8')
)