Skip to content

Commit

Permalink
create main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
YJ-928 committed May 17, 2023
1 parent 441db5f commit 10a3b6f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions birthdays.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,email,year,month,day
test,[email protected],1961,12,21
[Fill this in!]
6 changes: 6 additions & 0 deletions desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[.ShellClassInfo]
IconResource=C:\My Icons\Cornmanthe3rd-Plex-Other-python.ico,0
[ViewState]
Mode=
Vid=
FolderType=Generic
7 changes: 7 additions & 0 deletions letter_templates/letter_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dear [NAME],

Happy birthday!

All the best for the year!

YJ-928
7 changes: 7 additions & 0 deletions letter_templates/letter_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Hey [NAME],

Happy birthday! Have a wonderful time today and eat lots of cake!

Lots of love,

YJ-928
7 changes: 7 additions & 0 deletions letter_templates/letter_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dear [NAME],

It's your birthday! Have a great day!

All my love,

YJ-928
35 changes: 35 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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}"
)

0 comments on commit 10a3b6f

Please sign in to comment.