forked from wasmerio/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirthday-Manager.py
More file actions
56 lines (46 loc) · 1.6 KB
/
Copy pathBirthday-Manager.py
File metadata and controls
56 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import csv
import smtplib, ssl
message = """Hi {fname},
I wish you a very Happy Birthday.
I hope you had a great day."""
sender_address = "you@example.com"
sender_password = "examplePassword"
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_address, sender_password)
with open(r"birthday.csv") as birthdays:
reader = csv.reader(birthdays)
next(reader)
for fname, lname, email, dob in reader:
server.sendmail(
sender_address,
email,
message.format(fname=fname),
)
choice = input(
"""Do you wish to add or remove names from the csv file?
if you would like to add names type add
otherwise if you would like to remove names type remove
When you are finished, type exit
"""
)
if choice == "add":
new_data = input("Enter data as first name,lastname,email,date of birth: ")
new_data = new_data.split(",")
with open(r"birthday.csv", "r ") as file:
writer_object = csv.writer(file)
next(file)
writer_object.writerow(new_data)
elif choice == "remove":
lines = []
removal = input("Enter the first name of the person to be removed: ")
with open(r"birthday.csv", "r") as file:
reader = csv.reader(file)
for row in reader:
lines.append(row)
for fields in row:
if fields == removal:
lines.remove(row)
with open(r"birthday.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerows(lines)