Skip to content

Commit

Permalink
Merge pull request #20 from landog893/smarota17-email
Browse files Browse the repository at this point in the history
Smarota17 email
  • Loading branch information
lgaddy893 authored Dec 1, 2022
2 parents 565bc8e + 2959762 commit 5f022e6
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 87 deletions.
28 changes: 14 additions & 14 deletions data/people_data-copy.csv
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",,
2 changes: 2 additions & 0 deletions src/DBInit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def connect():
"Name" character varying COLLATE pg_catalog."default",
"Surname" character varying COLLATE pg_catalog."default",
"Birthday" character varying COLLATE pg_catalog."default",
"Email" character varying COLLATE pg_catalog."default",
"Notifications" character varying COLLATE pg_catalog."default",
"UserName" character varying COLLATE pg_catalog."default",
"Password" character varying COLLATE pg_catalog."default",
"Interests" character varying COLLATE pg_catalog."default",
Expand Down
98 changes: 80 additions & 18 deletions src/account.py
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
Expand All @@ -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()
35 changes: 19 additions & 16 deletions src/account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

class AccountInfo:

def create_account(self, name, surname='', birthday='',username='', password = '',interests='', wishlist='', friendlist=''):
def create_account(self, name, surname='', birthday='', email='', notifications='', username='', password = '',interests='', wishlist='', friendlist=''):

query = """Insert Into public."Account" ("Name","Surname","Birthday","UserName","Password","Interests","WishList","FriendList")
values(%s,%s,%s,%s,%s,%s,%s,%s) returning "ID" """
query = """Insert Into public."Account" ("Name","Surname","Birthday","Email","Notifications","UserName","Password","Interests","WishList","FriendList")
values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) returning "ID" """
conn = None
Checkquery = """Select * From "Account" WHERE "UserName" = %s;"""
acc = None
Expand All @@ -33,11 +33,6 @@ def create_account(self, name, surname='', birthday='',username='', password = '
return -2
cur.close()
# execute a statement
cur = conn.cursor()
cur.execute(query, (name, surname, birthday, username,password,interests,wishlist,friendlist))
acc = cur.fetchone()
print("create ID")
print(acc)
cur.close()
conn.commit()
cur.close()
Expand All @@ -51,8 +46,8 @@ def create_account(self, name, surname='', birthday='',username='', password = '

return acc

def update_account(self, ID, name='', surname='', birthday='',username='',password = '', interests='', wishlist = '', friendlist= ''):
query = """UPDATE "Account" Set "Name" = %s, "Surname" = %s, "Birthday" = %s, "UserName" = %s, "Password" = %s, "Interests" = %s, "WishList" = %s, "FriendList" = %s
def update_account(self, ID, name='', surname='', birthday='', email='', notifications='', username='',password = '', interests='', wishlist = '', friendlist= ''):
query = """UPDATE "Account" Set "Name" = %s, "Surname" = %s, "Birthday" = %s, "Email" = %s, "Notifications" = %s, "UserName" = %s, "Password" = %s, "Interests" = %s, "WishList" = %s, "FriendList" = %s
Where "ID" = %s"""
conn = None
success = True
Expand All @@ -63,7 +58,7 @@ def update_account(self, ID, name='', surname='', birthday='',username='',passwo
conn = psycopg2.connect(**params)
cur = conn.cursor()
# execute a statement
cur.execute(query, (name,surname,birthday,username,password,interests, wishlist, friendlist,ID))
cur.execute(query, (name,surname,birthday,email,notifications,username,password,interests, wishlist, friendlist,ID))
cur.close()
conn.commit()
cur.close()
Expand Down Expand Up @@ -106,7 +101,7 @@ def delete_account(self, ID):


def get_info(self, ID):
query = """Select "Name","Surname","Birthday","UserName","Password","Interests","WishList","FriendList"
query = """Select "Name","Surname","Birthday","Email","Notifications","UserName","Password","Interests","WishList","FriendList"
From "Account" WHERE "ID" = %s;"""
conn = None
user_info = None
Expand All @@ -133,7 +128,7 @@ def get_info(self, ID):
return user_info[0] if user_info else None

def get_account(self, username,password):
query = """Select "ID", "Name","Surname","Birthday","UserName","Password","Interests","WishList","FriendList"
query = """Select "ID", "Name","Surname","Birthday","Email","Notifications","UserName","Password","Interests","WishList","FriendList"
From "Account" WHERE "UserName" = %s;"""
conn = None
user_info = None
Expand All @@ -159,7 +154,7 @@ def get_account(self, username,password):

if user_info:
user_info = user_info[0]
if user_info[4] == password:
if user_info[7] == password:
return user_info
else:
return -2
Expand Down Expand Up @@ -207,6 +202,14 @@ def get_birthday(self, ID):
else:
result_dict = result.values
return result_dict[0][3]

# def get_email(self, ID):
# result, flag = self.search_ID(ID)
# if flag == -1:
# return -1
# else:
# result_dict = result.values
# return result_dict[0][4]

def get_interests(self, ID):
result, flag = self.search_ID(ID)
Expand All @@ -222,8 +225,8 @@ def get_wishlist(self, ID):
return -1
else:
result_dict = result.values
return result_dict[0][5]
return result_dict[0][6]

def add_wishlist(self, ID, items):
flag = 1
wl_str = self.get_wishlist(ID)
Expand Down
9 changes: 7 additions & 2 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from item_manager import ItemManager

# This class represents an item object. This item is a gift that a user can add to their wishlist.
class item():
# Initialization of the item object.
def __init__(self, title = '', desc = '', link = '', cost = '', ID = None):
if ID != None:
itemMan = ItemManager()
Expand All @@ -20,13 +23,13 @@ def __init__(self, title = '', desc = '', link = '', cost = '', ID = None):
self.cost = cost
self.itemID = int(self.create_item())



# This method creates an item.
def create_item(self):
itemMan = ItemManager()
item = itemMan.add_item(self.title, self.desc, self.link, self.cost)
return item

# This method modifies an item.
def modify_item(self, title, desc, link, cost):
itemMan = ItemManager()
self.title = title
Expand All @@ -35,10 +38,12 @@ def modify_item(self, title, desc, link, cost):
self.cost = cost
itemMan.update_item( self.itemID, title, desc, link, cost)

# This pulls an item for viewing.
def view_item(self):
itemMan = ItemManager()
return itemMan.get_item(self.itemID)

# This method deletes an item.
def delete_item(self):
itemMan = ItemManager()
itemMan.delete_item(self.itemID)
Expand Down
Loading

0 comments on commit 5f022e6

Please sign in to comment.