diff --git a/birthdays.csv b/birthdays.csv new file mode 100644 index 0000000..263a696 --- /dev/null +++ b/birthdays.csv @@ -0,0 +1,3 @@ +name,email,year,month,day +test,test@email.com,1961,12,21 +[Fill this in!] \ No newline at end of file diff --git a/desktop.ini b/desktop.ini new file mode 100644 index 0000000..191eabc --- /dev/null +++ b/desktop.ini @@ -0,0 +1,6 @@ +[.ShellClassInfo] +IconResource=C:\My Icons\Cornmanthe3rd-Plex-Other-python.ico,0 +[ViewState] +Mode= +Vid= +FolderType=Generic diff --git a/letter_templates/letter_1.txt b/letter_templates/letter_1.txt new file mode 100644 index 0000000..e4e8cd8 --- /dev/null +++ b/letter_templates/letter_1.txt @@ -0,0 +1,7 @@ +Dear [NAME], + +Happy birthday! + +All the best for the year! + +YJ-928 \ No newline at end of file diff --git a/letter_templates/letter_2.txt b/letter_templates/letter_2.txt new file mode 100644 index 0000000..353b1de --- /dev/null +++ b/letter_templates/letter_2.txt @@ -0,0 +1,7 @@ +Hey [NAME], + +Happy birthday! Have a wonderful time today and eat lots of cake! + +Lots of love, + +YJ-928 \ No newline at end of file diff --git a/letter_templates/letter_3.txt b/letter_templates/letter_3.txt new file mode 100644 index 0000000..5b26794 --- /dev/null +++ b/letter_templates/letter_3.txt @@ -0,0 +1,7 @@ +Dear [NAME], + +It's your birthday! Have a great day! + +All my love, + +YJ-928 \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..ef7dd10 --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +#To run and test the code you need to update 4 places: +# 1. Change MY_EMAIL/MY_PASSWORD to your own details. +# 2. Go to your email provider and make it allow less secure apps. +# 3. Update the SMTP ADDRESS to match your email provider. +# 4. Update birthdays.csv to contain today's month and day. + + +from datetime import datetime +import pandas +import random +import smtplib + +MY_EMAIL = "YOUR EMAIL" +MY_PASSWORD = "YOUR PASSWORD" + +today = datetime.now() +today_tuple = (today.month, today.day) + +data = pandas.read_csv("birthdays.csv") +birthdays_dict = {(data_row["month"], data_row["day"]): data_row for (index, data_row) in data.iterrows()} +if today_tuple in birthdays_dict: + birthday_person = birthdays_dict[today_tuple] + file_path = f"letter_templates/letter_{random.randint(1,3)}.txt" + with open(file_path) as letter_file: + contents = letter_file.read() + contents = contents.replace("[NAME]", birthday_person["name"]) + + with smtplib.SMTP("YOUR EMAIL PROVIDER SMTP SERVER ADDRESS") as connection: + connection.starttls() + connection.login(MY_EMAIL, MY_PASSWORD) + connection.sendmail( + from_addr=MY_EMAIL, + to_addrs=birthday_person["email"], + msg=f"Subject:Happy Birthday!\n\n{contents}" + )