|
| 1 | +import pandas as pd # Pandas library is used for importing and reading the data |
| 2 | +import datetime # datetime module is used for fetching the dates |
| 3 | +import smtplib # smtp library used for sending mail |
| 4 | +import os |
| 5 | + |
| 6 | +current_path = os.getcwd() |
| 7 | +print(current_path) |
| 8 | +os.chdir(current_path) # Changing the Path of the directory in which you are currently working |
| 9 | + |
| 10 | +GMAIL_ID = input("Enter your email: ") # Give your mail here from which you want to send the wishes |
| 11 | +GMAIL_PSWD = input("Enter password for your email mentioned above: ") # Give your mail password |
| 12 | + |
| 13 | + |
| 14 | +def sendEmail(to, sub, msg): |
| 15 | + print(f"Email to {to} sent: \nSubject: {sub} ,\nMessage: {msg}") |
| 16 | + s = smtplib.SMTP('smtp.gmail.com', 587) # creating server to send mail |
| 17 | + s.starttls() # start a TLS session |
| 18 | + s.login(GMAIL_ID, GMAIL_PSWD) # the function will login with your Gmail credentials |
| 19 | + s.sendmail(GMAIL_ID, to, f"Subject: {sub} \n\n {msg}") # sending the mail |
| 20 | + s.quit() |
| 21 | + |
| 22 | + |
| 23 | +if __name__ == "__main__": |
| 24 | + df = pd.read_excel("data.xlsx") # the datasheet where the data of the friends is stored |
| 25 | + today = datetime.datetime.now().strftime("%d-%m") |
| 26 | + yearNow = datetime.datetime.now().strftime("%Y") |
| 27 | + |
| 28 | + writeInd = [] |
| 29 | + for index, item in df.iterrows(): |
| 30 | + bday = item['Birthday'] |
| 31 | + bday = datetime.datetime.strptime(bday, "%d-%m-%Y") |
| 32 | + bday = bday.strftime("%d-%m") |
| 33 | + if(today == bday) and yearNow not in str(item['LastWishedYear']): |
| 34 | + sendEmail(item['Email'], "Happy Birthday", item['Dialogue']) # calling the sendmail function |
| 35 | + writeInd.append(index) |
| 36 | + |
| 37 | + if writeInd != None: |
| 38 | + for i in writeInd: |
| 39 | + oldYear = df.loc[i, 'LastWishedYear'] |
| 40 | + df.loc[i, 'LastWishedYear'] = str(oldYear) + ", " + str(yearNow) |
| 41 | + |
| 42 | + df.to_excel('data.xlsx', index=False) |
0 commit comments