-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathAuto_Message_Sender.py
120 lines (87 loc) · 2.89 KB
/
Auto_Message_Sender.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# import required packages
import pandas as pd
import datetime
import smtplib
import time
import requests
from win10toast import ToastNotifier
# your gmail credentials here
GMAIL_ID = 'your_email_here'
GMAIL_PWD = 'your_password_here'
# for desktop notification
toast = ToastNotifier()
# define a function for sending email
def sendEmail(to, sub, msg):
# connection to gmail
gmail_obj = smtplib.SMTP('smtp.gmail.com', 587)
# starting the session
gmail_obj.starttls()
# login using credentials
gmail_obj.login(GMAIL_ID, GMAIL_PWD)
# sending email
gmail_obj.sendmail(GMAIL_ID, to,
f"Subject : {sub}\n\n{msg}")
# quit the session
gmail_obj.quit()
print("Email sent to " + str(to) + " with subject "
+ str(sub) + " and message :" + str(msg))
toast.show_toast("Email Sent!" ,
f"{name} was sent e-mail",
threaded = True,
icon_path = None,
duration = 6)
while toast.notification_active():
time.sleep(0.1)
# define a function for sending sms
def sendsms(to, msg, name, sub):
url = "https://www.fast2sms.com/dev/bulk"
payload = f"sender_id=FSTSMS&message={msg}&language=english&route=p&numbers={to}"
headers = {
'authorization': "API_KEY_HERE",
'Content-Type': "application/x-www-form-urlencoded",
'Cache-Control': "no-cache",
}
response_obj = requests.request("POST", url,
data = payload,
headers = headers)
print(response_obj.text)
print("SMS sent to " + str(to) + " with subject :" +
str(sub) + " and message :" + str(msg))
toast.show_toast("SMS Sent!" ,
f"{name} was sent message",
threaded = True,
icon_path = None,
duration = 6)
while toast.notification_active():
time.sleep(0.1)
# driver code
if __name__=="__main__":
# read the excel sheet having all the details
dataframe = pd.read_excel("excelsheet.xlsx")
# today date in format : DD-MM
today = datetime.datetime.now().strftime("%d-%m")
# current year in format : YY
yearNow = datetime.datetime.now().strftime("%Y")
# writeindex list
writeInd = []
for index,item in dataframe.iterrows():
msg = "Many Many Happy Returns of the day dear " + str(item['NAME'])
# stripping the birthday in excel
# sheet as : DD-MM
bday = item['Birthday'].strftime("%d-%m")
# condition checking
if (today == bday) and yearNow not in str(item['Year']):
# calling the sendEmail function
sendEmail(item['Email'], "Happy Birthday",
msg)
# calling the sendsms function
sendsms(item['Contact'], msg, item['NAME'],
"Happy Birthday")
writeInd.append(index)
for i in writeInd:
yr = dataframe.loc[i,'Year']
# this will record the years in which
# email has been sent
dataframe.loc[i,'Year'] = str(yr) + ',' + str(yearNow)
dataframe.to_excel('excelsheet.xlsx',
index = False)