Amazing-Python-Scripts

Форк
0
53 строки · 1.8 Кб
1
# Pandas library is used for importing and reading the data
2
import pandas as pd
3
# datetime module is used for fetching the dates
4
import datetime
5
import smtplib															# smtp library used for sending mail
6
import os
7

8
current_path = os.getcwd()
9
print(current_path)
10
# Changing the Path of the directory in which you are currently working
11
os.chdir(current_path)
12

13
# Give your mail here from which you want to send the wishes
14
GMAIL_ID = input("Enter your email: ")
15
# Give your mail password
16
GMAIL_PSWD = input("Enter password for your email mentioned above: ")
17

18

19
def sendEmail(to, sub, msg):
20
    print(f"Email to {to} sent: \nSubject: {sub} ,\nMessage: {msg}")
21
    # creating server to send mail
22
    s = smtplib.SMTP('smtp.gmail.com', 587)
23
    # start a TLS session
24
    s.starttls()
25
    # the function will login with your Gmail credentials
26
    s.login(GMAIL_ID, GMAIL_PSWD)
27
    # sending the mail
28
    s.sendmail(GMAIL_ID, to, f"Subject: {sub} \n\n {msg}")
29
    s.quit()
30

31

32
if __name__ == "__main__":
33
    # the datasheet where the data of the friends is stored
34
    df = pd.read_excel("data.xlsx")
35
    today = datetime.datetime.now().strftime("%d-%m")
36
    yearNow = datetime.datetime.now().strftime("%Y")
37

38
    writeInd = []
39
    for index, item in df.iterrows():
40
        bday = item['Birthday']
41
        bday = datetime.datetime.strptime(bday, "%d-%m-%Y")
42
        bday = bday.strftime("%d-%m")
43
        if (today == bday) and yearNow not in str(item['LastWishedYear']):
44
            # calling the sendmail function
45
            sendEmail(item['Email'], "Happy Birthday", item['Dialogue'])
46
            writeInd.append(index)
47

48
    if writeInd != None:
49
        for i in writeInd:
50
            oldYear = df.loc[i, 'LastWishedYear']
51
            df.loc[i, 'LastWishedYear'] = str(oldYear) + ", " + str(yearNow)
52

53
    df.to_excel('data.xlsx', index=False)
54

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.