-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier.py
28 lines (27 loc) · 989 Bytes
/
notifier.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
import smtplib
import stocks
from plyer import notification
from dotenv import load_dotenv
import os
import json
output = stocks.getDividendDetails()
if isinstance(output,str):
notification.notify(title="", app_icon="dollar.ico", message=output, timeout=10)
else:
dividends = json.dumps(output,indent=4)
try:
load_dotenv()
s = smtplib.SMTP("smtp.gmail.com", 587)
# start TLS for security
s.starttls()
# Authentication
s.login(os.getenv("SENDER"), os.getenv("PASSWD"))
# message to be sent
message = dividends
# sending the mail
s.sendmail(os.getenv("SENDER"), os.getenv("RECEIVER"), message)
# terminating the session
s.quit()
notification.notify(title="", app_icon="dollar.ico", message="Upcoming dividends sent to email", timeout=10)
except:
notification.notify(title="", app_icon="dollar.ico", message="Not able to send ex date of dividends", timeout=10)