Amazing-Python-Scripts
53 строки · 1.8 Кб
1# Pandas library is used for importing and reading the data
2import pandas as pd3# datetime module is used for fetching the dates
4import datetime5import smtplib # smtp library used for sending mail6import os7
8current_path = os.getcwd()9print(current_path)10# Changing the Path of the directory in which you are currently working
11os.chdir(current_path)12
13# Give your mail here from which you want to send the wishes
14GMAIL_ID = input("Enter your email: ")15# Give your mail password
16GMAIL_PSWD = input("Enter password for your email mentioned above: ")17
18
19def sendEmail(to, sub, msg):20print(f"Email to {to} sent: \nSubject: {sub} ,\nMessage: {msg}")21# creating server to send mail22s = smtplib.SMTP('smtp.gmail.com', 587)23# start a TLS session24s.starttls()25# the function will login with your Gmail credentials26s.login(GMAIL_ID, GMAIL_PSWD)27# sending the mail28s.sendmail(GMAIL_ID, to, f"Subject: {sub} \n\n {msg}")29s.quit()30
31
32if __name__ == "__main__":33# the datasheet where the data of the friends is stored34df = pd.read_excel("data.xlsx")35today = datetime.datetime.now().strftime("%d-%m")36yearNow = datetime.datetime.now().strftime("%Y")37
38writeInd = []39for index, item in df.iterrows():40bday = item['Birthday']41bday = datetime.datetime.strptime(bday, "%d-%m-%Y")42bday = bday.strftime("%d-%m")43if (today == bday) and yearNow not in str(item['LastWishedYear']):44# calling the sendmail function45sendEmail(item['Email'], "Happy Birthday", item['Dialogue'])46writeInd.append(index)47
48if writeInd != None:49for i in writeInd:50oldYear = df.loc[i, 'LastWishedYear']51df.loc[i, 'LastWishedYear'] = str(oldYear) + ", " + str(yearNow)52
53df.to_excel('data.xlsx', index=False)54