Skip to content

Commit a555119

Browse files
committed
Updated paths to be relative, removed credentials, added sample csv file
1 parent c2d8668 commit a555119

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

Automating Emails/Birthday-Manager.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
import csv
22
import smtplib, ssl
33

4-
message="""Hi {fname}, Wish you a very Happy birthday.
5-
Hope you had a great time."""
4+
message = """Hi {fname},
5+
I wish you a very Happy Birthday.
6+
I hope you had a great day."""
67

7-
sender_address="forpythonbirthdayproject@gmail.com"
8-
sender_password="qwerty@12345"
8+
sender_address = "you@example.com"
9+
sender_password = "examplePassword"
910

1011
context = ssl.create_default_context()
1112
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
12-
server.login(sender_address,sender_password)
13+
server.login(sender_address, sender_password)
1314

14-
with open(r"C:\Users\sriva\OneDrive\Desktop\VS Code\Python\birthday.csv") as file:
15-
reader=csv.reader(file)
15+
with open(r"birthday.csv") as birthdays:
16+
reader = csv.reader(birthdays)
1617
next(reader)
17-
for fname,lname,email,dob in reader:
18+
for fname, lname, email, dob in reader:
1819
server.sendmail(
1920
sender_address,
2021
email,
2122
message.format(fname=fname),
2223
)
2324

24-
add=input(
25-
"""Do you wish to add or remove names to the csv file?
26-
if you want add names type add
27-
otherwise if you want remove names type remove
28-
if you wish to exit, type exit
25+
choice = input(
26+
"""Do you wish to add or remove names from the csv file?
27+
if you would like to add names type add
28+
otherwise if you would like to remove names type remove
29+
When you are finished, type exit
2930
"""
3031
)
31-
32-
if add=="add":
33-
new_data=input("Enter data as first name,lastname,email,date of birth: ")
34-
new_data=new_data.split(",")
35-
with open(r"C:\Users\sriva\OneDrive\Desktop\VS Code\Python\birthday.csv",'r+') as file:
36-
writer_object=csv.writer(file)
32+
33+
if choice == "add":
34+
new_data = input("Enter data as first name,lastname,email,date of birth: ")
35+
new_data = new_data.split(",")
36+
with open(r"birthday.csv", "r ") as file:
37+
writer_object = csv.writer(file)
3738
next(file)
3839
writer_object.writerow(new_data)
39-
elif add=="remove":
40-
lines=[]
41-
removal=input("Enter the first name of the person to be removed: ")
42-
with open(r"C:\Users\sriva\OneDrive\Desktop\VS Code\Python\birthday.csv",'r') as file:
43-
reader=csv.reader(file)
40+
elif choice == "remove":
41+
lines = []
42+
removal = input("Enter the first name of the person to be removed: ")
43+
with open(r"birthday.csv", "r") as file:
44+
reader = csv.reader(file)
45+
4446
for row in reader:
4547
lines.append(row)
48+
4649
for fields in row:
47-
if fields==removal:
50+
if fields == removal:
4851
lines.remove(row)
49-
with open(r"C:\Users\sriva\OneDrive\Desktop\VS Code\Python\birthday.csv",'w',newline="") as file:
50-
writer=csv.writer(file)
51-
writer.writerows(lines)
52-
53-
5452

53+
with open(r"birthday.csv", "w", newline="") as file:
54+
writer = csv.writer(file)
55+
writer.writerows(lines)
5556

Automating Emails/birthday.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
John,Smith,jsmith@example.com,01011990

0 commit comments

Comments
 (0)