-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from landog893/smarota17-email
Smarota17 email
- Loading branch information
Showing
6 changed files
with
257 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
ID,Name,Surname,Birthday,Interests,WishList,FriendList | ||
1,Yagmur Basak,Bayraktar,12/17/1994,"Dancing, Reading, Cooking, Ballet, Writing","3,5,11,17"," 5, 6, 2, 3" | ||
2,Murat,Bayraktar,09-07-95,"Basketball, Football, Electronics","3,5",1 | ||
3,Jane,Doe,01-01-00,"Hiking, Climbing, Bungee Jumping",5,4 | ||
4,John,Doe,02-02-99,"Painting, Sculpting, Art","2, 3","3, 5" | ||
5,David,Beckham,10/30/2012,"Cookie Art, Puzzles, Pets","1, 4, 2","1, 3" | ||
6,Albert,Einstein,02-05-04,"Zodiac Signs, Fitness",,4 | ||
7,Taylor,Swift,5/28/1957,"Weaving, DIY, Painting",6, | ||
8,Bruce,Wayne,10-10-10,Technology,, | ||
9,Tinker,Bell,04-04-00,Spellcasting,"8, 1, 4, 9, 10",5 | ||
10,Jon,Snow,12/31/1992,,"6, 9,10", | ||
11,Hannah,Montana,05-05-95,"Singing, Dancing",, | ||
12,Barney,Stinson,8/25/1972,"Women, suits",14,1 | ||
13,Michael Gary,Scott,05-05-65,"Spy Novels, Improvisation, Sales",, | ||
ID,Name,Surname,Birthday,Email,Notifications,Interests,WishList,FriendList | ||
1,Yagmur Basak,Bayraktar,12/17/1994,[email protected],On,"Dancing, Reading, Cooking, Ballet, Writing","3,5,11,17"," 5, 6, 2, 3" | ||
2,Murat,Bayraktar,9/7/1995,[email protected],Off,"Basketball, Football, Electronics","3,5",1 | ||
3,Jane,Doe,1/1/2000,[email protected],On,"Hiking, Climbing, Bungee Jumping",5,4 | ||
4,John,Doe,2/2/1999,[email protected],Off,"Painting, Sculpting, Art","2, 3","3, 5" | ||
5,David,Beckham,10/30/2012,[email protected],On,"Cookie Art, Puzzles, Pets","1, 4, 2","1, 3" | ||
6,Albert,Einstein,2/5/2004,[email protected],Off,"Zodiac Signs, Fitness",,4 | ||
7,Taylor,Swift,5/28/1957,[email protected],On,"Weaving, DIY, Painting",6, | ||
8,Bruce,Wayne,10/10/2010,[email protected],Off,Technology,, | ||
9,Tinker,Bell,4/4/2000,[email protected],On,Spellcasting,"8, 1, 4, 9, 10",5 | ||
10,Jon,Snow,12/31/1992,[email protected],Off,,"6, 9,10", | ||
11,Hannah,Montana,5/5/1995,[email protected],On,"Singing, Dancing",, | ||
12,Barney,Stinson,8/25/1972,[email protected],Off,"Women, suits",14,1 | ||
13,Michael Gary,Scott,5/5/1965,[email protected],On,"Spy Novels, Improvisation, Sales",, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
from account_info import AccountInfo | ||
from datetime import datetime, timedelta | ||
import smtplib, ssl | ||
from item import item | ||
from email.mime.text import MIMEText | ||
from email.mime.multipart import MIMEMultipart | ||
import streamlit as st | ||
|
||
# This class represents an account object that a user creates to interact with the code. | ||
class Account(): | ||
def __init__(self, name='', surname='', birthday='', username='',password = '', interests='', wishlist='', friendlist='', ID = None): | ||
def __init__(self, name='', surname='', birthday='', email='', notifications='', username='',password = '', interests='', wishlist='', friendlist='', ID = None): | ||
if ID != None: | ||
accountMan = AccountInfo() | ||
info = accountMan.get_info(ID) | ||
if info: | ||
self.name = info[0] | ||
self.surname = info[1] | ||
self.birthday = info[2] | ||
self.username = info[3] | ||
self.password = info[4] | ||
self.interests = info[5] | ||
self.wishlist = info[6] | ||
self.friendlist = info[7] | ||
self.email = info[3] | ||
self.notifications = info[4] | ||
self.username = info[5] | ||
self.password = info[6] | ||
self.interests = info[7] | ||
self.wishlist = info[8] | ||
self.friendlist = info[9] | ||
self.ID = ID | ||
else: | ||
raise ValueError | ||
else: | ||
self.name = name | ||
self.surname = surname | ||
self.birthday = birthday | ||
self.email = email | ||
self.notifications = notifications | ||
self.username = username | ||
self.password = password | ||
self.interests = interests | ||
|
@@ -40,34 +50,86 @@ def __init__(self, name='', surname='', birthday='', username='',password = '', | |
|
||
def create_account(self): | ||
accountMan = AccountInfo() | ||
acc = accountMan.create_account(self.name, self.surname, self.birthday,self.username, self.password,self.interests, self.wishlist, self.friendlist) | ||
acc = accountMan.create_account(self.name, self.surname, self.birthday, self.email, self.notifications, self.username, self.password,self.interests, self.wishlist, self.friendlist) | ||
return acc | ||
|
||
# This method pulls the account to allow the user the view information. | ||
def view_account(self): | ||
accountMan = AccountInfo() | ||
return accountMan.get_info(self.ID) | ||
|
||
def update_account(self, name='', surname='', birthday='', username='',password = '', interests='',wishlist = '', friendlist= ''): | ||
def update_account(self, name='', surname='', birthday='', email='', notifications='', username='',password = '', interests='',wishlist = '', friendlist= ''): | ||
self.name = name | ||
self.surname = surname | ||
self.birthday = birthday | ||
self.email = email | ||
self.notifications = notifications | ||
self.username = username | ||
self.password = password | ||
self.interests = interests | ||
self.wishlist = wishlist | ||
self.friendlist = friendlist | ||
accountMan = AccountInfo() | ||
accountMan.update_account(self.ID, name, surname, birthday,username, password,interests, wishlist, friendlist) | ||
accountMan.update_account(self.ID, name, surname, birthday, email, notifications, username, password,interests, wishlist, friendlist) | ||
|
||
# This method is used to send birthday reminder emails if a user has their email notification | ||
# preferences on. The method loops through the friends list, and if the friend has their email | ||
# preferences on as well, an email is sent using SMTP. The method runs every time the program is | ||
# loaded (checks if the birthday is in 1 week) or when the user clicks the "Send Notification" button | ||
# in the profile. | ||
def send_reminder_email(self): | ||
name = self.name | ||
birthday = self.birthday | ||
print(birthday) | ||
b = birthday.rpartition('/')[0] + birthday.rpartition('/')[1] | ||
b = b[:-1] | ||
|
||
friendlist = self.friendlist | ||
friendl = friendlist.split(',') | ||
friendobj = [Account(ID=int(f)) for f in friendl if f.isnumeric()] | ||
|
||
# #acc = Account('Hannah', 'Montana', '05/05/1995', 'Singing, Dancing') | ||
# #acc.view_account() | ||
# acc = Account(ID=1) | ||
# ints = (acc.interests.to_string(index=False)).replace("\"", "") | ||
# ints += ", Ballet" | ||
# # print(ints) | ||
# wishes = (acc.wishlist.to_string(index=False)) | ||
# acc.update_account(acc.name.to_string(index=False), acc.surname.to_string(index=False), acc.birthday.to_string(index=False), ints, acc.wishlist.to_string(index=False), acc.friendlist.to_string(index=False)) | ||
|
||
|
||
items = (self.wishlist).replace("\"", "").split(",") | ||
items = [int(item) for item in items if item.isnumeric()] | ||
item_objs = [item(ID=id) for id in items] | ||
|
||
notifications = self.notifications | ||
port = 587 | ||
smtp_server = "smtp.office365.com" | ||
sender_email = "[email protected]" | ||
password = "G1ft3r#212!" | ||
|
||
if (notifications == "Off"): | ||
print("Please turn email notifications on.") | ||
elif (password == "REPLACE"): | ||
print("Please replace the password field with your Outlook account's password.") | ||
else: | ||
# construct wishlist string | ||
wishlistString = "\n" | ||
for i in item_objs: | ||
wishlistString += " - " + i.title + " ($" + str(i.cost) + "): " + i.link + "\n" | ||
|
||
message = """Buy """ + name + """ the perfect gift for their birthday on """ + b + """.\nHere are some items on their wishlist:\n """ + wishlistString | ||
|
||
for friend in friendobj: | ||
if (friend.notifications == "On"): | ||
receiver_email = friend.email | ||
msg = MIMEMultipart() | ||
msg['Subject'] = "Gifter-2: " + name + "'s Birthday is Coming Up" | ||
msg['From'] = sender_email | ||
msg['To'] = receiver_email | ||
|
||
body = MIMEText(message, "plain") | ||
msg.attach(body) | ||
|
||
context = ssl.create_default_context() | ||
with smtplib.SMTP(smtp_server, port) as server: | ||
server.ehlo() | ||
server.starttls(context=context) | ||
server.ehlo() | ||
server.login(sender_email, password) | ||
print("logged in") | ||
print("attempting to send mail") | ||
server.sendmail(sender_email, receiver_email, msg.as_string()) | ||
print("message sent") | ||
server.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.