Skip to content

Commit

Permalink
Create notification_manager.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkit69 committed Sep 21, 2023
1 parent dcfd4c8 commit 347f3c9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions day40 /notification_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import smtplib
import requests

BOT_TOKEN = "******************************************"
BOT_CHATID = "*********"
MAIL_PROVIDER_SMTP_ADDRESS = "smtp.outlook.com"
MY_EMAIL = "***********************"
MY_PASSWORD = "p*********"


class NotificationManager:

def telegram_bot_send_text(self, bot_message):
bot_token = BOT_TOKEN
bot_chatID = BOT_CHATID
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID \
+ '&parse_mode=Markdown&text=' + bot_message
bot_response = requests.get(send_text)
return bot_response.json()

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=email,
msg=f"Subject:New Low Price Flight!\n\n{message}\n{google_flight_link}".encode('utf-8')
)

0 comments on commit 347f3c9

Please sign in to comment.