|
| 1 | +# import required packages |
| 2 | +import pandas as pd |
| 3 | +import datetime |
| 4 | +import smtplib |
| 5 | +import time |
| 6 | +import requests |
| 7 | +from win10toast import ToastNotifier |
| 8 | + |
| 9 | +# your gmail credentials here |
| 10 | +GMAIL_ID = 'your_email_here' |
| 11 | +GMAIL_PWD = 'your_password_here' |
| 12 | + |
| 13 | +# for desktop notification |
| 14 | +toast = ToastNotifier() |
| 15 | + |
| 16 | +# define a function for sending email |
| 17 | +def sendEmail(to, sub, msg): |
| 18 | + |
| 19 | + # connection to gmail |
| 20 | + gmail_obj = smtplib.SMTP('smtp.gmail.com', 587) |
| 21 | + |
| 22 | + # starting the session |
| 23 | + gmail_obj.starttls() |
| 24 | + |
| 25 | + # login using credentials |
| 26 | + gmail_obj.login(GMAIL_ID, GMAIL_PWD) |
| 27 | + |
| 28 | + # sending email |
| 29 | + gmail_obj.sendmail(GMAIL_ID, to, |
| 30 | + f"Subject : {sub}\n\n{msg}") |
| 31 | + |
| 32 | + # quit the session |
| 33 | + gmail_obj.quit() |
| 34 | + |
| 35 | + print("Email sent to " + str(to) + " with subject " |
| 36 | + + str(sub) + " and message :" + str(msg)) |
| 37 | + |
| 38 | + toast.show_toast("Email Sent!" , |
| 39 | + f"{name} was sent e-mail", |
| 40 | + threaded = True, |
| 41 | + icon_path = None, |
| 42 | + duration = 6) |
| 43 | + |
| 44 | + while toast.notification_active(): |
| 45 | + time.sleep(0.1) |
| 46 | + |
| 47 | +# define a function for sending sms |
| 48 | +def sendsms(to, msg, name, sub): |
| 49 | + |
| 50 | + url = "https://www.fast2sms.com/dev/bulk" |
| 51 | + payload = f"sender_id=FSTSMS&message={msg}&language=english&route=p&numbers={to}" |
| 52 | + |
| 53 | + headers = { |
| 54 | + 'authorization': "API_KEY_HERE", |
| 55 | + 'Content-Type': "application/x-www-form-urlencoded", |
| 56 | + 'Cache-Control': "no-cache", |
| 57 | + } |
| 58 | + |
| 59 | + response_obj = requests.request("POST", url, |
| 60 | + data = payload, |
| 61 | + headers = headers) |
| 62 | + print(response_obj.text) |
| 63 | + print("SMS sent to " + str(to) + " with subject :" + |
| 64 | + str(sub) + " and message :" + str(msg)) |
| 65 | + |
| 66 | + toast.show_toast("SMS Sent!" , |
| 67 | + f"{name} was sent message", |
| 68 | + threaded = True, |
| 69 | + icon_path = None, |
| 70 | + duration = 6) |
| 71 | + |
| 72 | + while toast.notification_active(): |
| 73 | + time.sleep(0.1) |
| 74 | + |
| 75 | +# driver code |
| 76 | +if __name__=="__main__": |
| 77 | + |
| 78 | + # read the excel sheet having all the details |
| 79 | + dataframe = pd.read_excel("excelsheet.xlsx") |
| 80 | + |
| 81 | + # today date in format : DD-MM |
| 82 | + today = datetime.datetime.now().strftime("%d-%m") |
| 83 | + |
| 84 | + # current year in format : YY |
| 85 | + yearNow = datetime.datetime.now().strftime("%Y") |
| 86 | + |
| 87 | + # writeindex list |
| 88 | + writeInd = [] |
| 89 | + |
| 90 | + for index,item in dataframe.iterrows(): |
| 91 | + |
| 92 | + msg = "Many Many Happy Returns of the day dear " + str(item['NAME']) |
| 93 | + |
| 94 | + # stripping the birthday in excel |
| 95 | + # sheet as : DD-MM |
| 96 | + bday = item['Birthday'].strftime("%d-%m") |
| 97 | + |
| 98 | + # condition checking |
| 99 | + if (today == bday) and yearNow not in str(item['Year']): |
| 100 | + |
| 101 | + # calling the sendEmail function |
| 102 | + sendEmail(item['Email'], "Happy Birthday", |
| 103 | + msg) |
| 104 | + |
| 105 | + # calling the sendsms function |
| 106 | + sendsms(item['Contact'], msg, item['NAME'], |
| 107 | + "Happy Birthday") |
| 108 | + |
| 109 | + writeInd.append(index) |
| 110 | + |
| 111 | + for i in writeInd: |
| 112 | + |
| 113 | + yr = dataframe.loc[i,'Year'] |
| 114 | + |
| 115 | + # this will record the years in which |
| 116 | + # email has been sent |
| 117 | + dataframe.loc[i,'Year'] = str(yr) + ',' + str(yearNow) |
| 118 | + |
| 119 | + dataframe.to_excel('excelsheet.xlsx', |
| 120 | + index = False) |
0 commit comments