Skip to content

Commit 65a5916

Browse files
authored
Create notification_manager.py
1 parent aff22ad commit 65a5916

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

day40/notification_manager.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import smtplib
2+
import requests
3+
4+
BOT_TOKEN = "******************************************"
5+
BOT_CHATID = "*********"
6+
MAIL_PROVIDER_SMTP_ADDRESS = "smtp.outlook.com"
7+
MY_EMAIL = "***********************"
8+
MY_PASSWORD = "p*********"
9+
10+
11+
class NotificationManager:
12+
13+
def telegram_bot_send_text(self, bot_message):
14+
bot_token = BOT_TOKEN
15+
bot_chatID = BOT_CHATID
16+
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID \
17+
+ '&parse_mode=Markdown&text=' + bot_message
18+
bot_response = requests.get(send_text)
19+
return bot_response.json()
20+
21+
def send_emails(self, emails, message, google_flight_link):
22+
with smtplib.SMTP(MAIL_PROVIDER_SMTP_ADDRESS) as connection:
23+
connection.starttls()
24+
connection.login(MY_EMAIL, MY_PASSWORD)
25+
for email in emails:
26+
connection.sendmail(
27+
from_addr=MY_EMAIL,
28+
to_addrs=email,
29+
msg=f"Subject:New Low Price Flight!\n\n{message}\n{google_flight_link}".encode('utf-8')
30+
)

0 commit comments

Comments
 (0)