-
Notifications
You must be signed in to change notification settings - Fork 0
/
Facebook.py
322 lines (291 loc) · 12.8 KB
/
Facebook.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import sys
from User import User
from Group import Group
from helper import clear
from Database import Database
import client
usersList = []
groupsList = []
class Facebook:
def __init__(self):
self.usersList = usersList
self.groupsList = groupsList
def get_usersList(self):
return(self.usersList)
def get_groupsList(self):
return(self.groupsList)
def add_user(self, firstName, lastName, email, password, dob, bio):
user = User(firstName, lastName, email, password, dob, bio, "","","")
self.usersList.append(user)
return user
def addgroup(self,groupName):
self.groupsList.append(groupName)
def user_exists(self, email):
for user in self.usersList:
if user.get_email() == email:
return True
return False
def validate_user(self, email, password):
for user in self.usersList:
if user.get_email() == email:
if user.get_password() == password:
return True
else:
return False
def get_user_details(self, email):
for user in self.usersList:
if user.get_email() == email:
return user.get_user_details()
def display_user_posts(self,email):
db = Database()
posts = db.get_post_from_person_node_details(email)
myPosts = posts.split("\n")
clear()
print("|--------------------------------------------|")
print("|------------------MY POSTS------------------|")
print("|--------------------------------------------|")
for post in myPosts:
print(" ",post)
print("|--------------------------------------------|")
def create_post(self,email):
db = Database()
print("|--------------------------------------------|")
print("|-----------------CREATE POST----------------|")
print("|--------------------------------------------|")
post = input("\n What is in your mind? \n\n ")
db.add_post_to_person_node(email,post)
clear()
print("|--------------------------------------------|")
print(" Successfully created the post!! ")
print("|--------------------------------------------|")
def showUsers(self):
db = Database()
print("|--------------------------------------------------|")
print("|------------------LIST OF USERS-------------------|")
print("|--------------------------------------------------|")
users = db.show_user_nodes()
for user in users:
print(" ",user)
print("|--------------------------------------------------|")
def addFriend(self, email, friend_name):
db = Database()
if db.get_name(email) == friend_name:
clear()
print("|----------------------------------------------------------------|")
print(" You cannot add yourself to your friends list")
print("|----------------------------------------------------------------|")
return
for name in db.my_friends(email):
if name == friend_name:
clear()
print("|--------------------------------------------|")
print(" User is already your friend ")
print("|--------------------------------------------|")
return
db.add_friend_to_person_node(email,friend_name)
clear()
print("|----------------------------------------------------------------|")
print(" ",friend_name," successfully added to your friend list ")
print("|----------------------------------------------------------------|")
return
def showFriends(self,email):
db = Database()
friends = db.my_friends(email)
clear()
print("|--------------------------------------------|")
print("|-----------------MY FRIENDS-----------------|")
print("|--------------------------------------------|")
if(len(friends) != 0):
for friend in friends:
print(" ",friend)
else :
print(" YOU HAVE NO FRIENDS ")
print("|--------------------------------------------|")
def is_friend(self, email, friend_name):
for user in self.usersList:
if user.get_email() == email:
if friend_name in user.get_friends():
return True
else:
return False
def showFriendsPost(self,email, friend_name):
db = Database()
myFriends = db.my_friends(email)
if friend_name in myFriends:
posts = db.get_friends_post_from_person_node_details(friend_name)
friend_Posts = posts.split("\n")
clear()
print("|--------------------------------------------|")
print("|---------",friend_name,"\'s"" Posts---------|")
print("|--------------------------------------------|")
if(len(friend_Posts) != 0):
for post in friend_Posts:
print(" ",post)
else:
print(" NO POSTS YET ")
print("|--------------------------------------------|")
else:
clear()
print("|--------------------------------------------|")
print(" ",friend_name ,"is not your friend")
print("|--------------------------------------------|")
def createGroup(self, email):
db = Database()
print("|---------------------------------|")
print(" Creating new group ")
print("|---------------------------------|")
groupName=input("\n Enter the name of the new group : ")
if groupName in db.show_group_nodes():
clear()
print("|---------------------------------------|")
print(" Group already exist with that name ")
print("|---------------------------------------|")
return
db.create_group_node(groupName," ",email)
clear()
print("|---------------------------------------|")
print(" New group created successfully! ")
print("|---------------------------------------|")
def showGroups(self):
db = Database()
groups = db.show_group_nodes()
if len(groups)>0:
print("|--------------------------------------------------|")
print("|-------------------GROUPS LIST--------------------|")
print("|--------------------------------------------------|")
for group in groups:
print(" ",group)
print("|--------------------------------------------------|")
return True
else:
print("|---------------------------------|")
print(" No groups present ")
print("|---------------------------------|")
return False
def joinGroup(self,email):
db = Database()
flag = self.showGroups()
if (flag == False):
print("|---------------------------------|")
print(" create a group to join ")
print("|---------------------------------|")
return
print("|---------------------------------|")
print(" Joining group ")
print("|---------------------------------|")
groupName=input("\n Enter the name of the group you wish to join : ")
if groupName in db.my_groups(email):
clear()
print("|---------------------------------|")
print(" Already a group member ")
print("|---------------------------------|")
return
db.join_group_node(groupName,email)
print("|------------------------------------------------------------|")
print(" You are successfully added to ",groupName," group ")
print("|------------------------------------------------------------|")
def showMyGroups(self, email):
db = Database()
groups = db.my_groups(email)
clear()
if len(groups)>0:
print("|--------------------------------------------------|")
print("|------------------- MY GROUPS --------------------|")
print("|--------------------------------------------------|")
for group in groups:
print(" ", group)
print("|--------------------------------------------------|")
return True
else:
print("|---------------------------------|")
print(" You are not part of any group ")
print("|---------------------------------|")
return False
def leaveGroup(self,email):
db = Database()
flag = self.showMyGroups(email)
if (flag == False):
return
print("|---------------------------------|")
print(" Leaving group ")
print("|---------------------------------|")
group=input("\n Enter the name of the group you want to leave : ")
if group in db.my_groups(email):
db.leave_group(group,email)
clear()
print("|---------------------------------|")
print(" You have left the group ")
print("|---------------------------------|")
else:
print("|---------------------------------|")
print(" Not a valid group name ")
print("|---------------------------------|")
def post_in_group(self,email):
db = Database()
flag = self.showMyGroups(email)
if (flag == False):
return
print("|---------------------------------|")
print(" Creating group post ")
print("|---------------------------------|")
print("\n Note: To post the you have to be the member of the group.")
group_name = input("\n Enter the group name in which you want to post: ")
group_post = input("\n Enter the post message: ")
if group_name in db.my_groups(email):
db.add_post_to_group_node(group_name,email,group_post)
clear()
print("|---------------------------------|")
print(" Created a group post ")
print("|---------------------------------|")
return
else:
clear()
print("|------------------------------------------|")
print(" You are not a member of the group to post ")
print("|------------------------------------------|")
return
print("|------------------------------------------|")
print(" There is no such group to create the post ")
print("|------------------------------------------|")
def showGroupPosts(self,email):
db = Database()
flag = self.showMyGroups(email)
if (flag == False):
return
print("|---------------------------------|")
print(" Group posts ")
print("|---------------------------------|")
group_name=input("\n Enter the group name to view the posts :")
if group_name in db.show_group_nodes():
posts = db.get_posts_from_group_node_details(group_name)
groupPosts = posts.split("\n")
clear()
print("|--------------------------------------------|")
print("|---------",group_name,"\'s"" Posts---------|")
print("|--------------------------------------------|")
if(len(groupPosts) != 0):
for post in groupPosts:
print(" ",post)
else:
print(" NO POSTS YET ")
print("|--------------------------------------------|")
else:
print("|---------------------------------------------|")
print(" There is no such group to display the posts ")
print("|---------------------------------------------|")
def chatRoom(self,email):
db = Database()
print("|---------------------------------|")
print(" Welcome Chat Room ")
print("|---------------------------------|")
message=input("\n Enter your message :")
user_message(message)
chat_message = email + " : " + message
db.create_chat_message(chat_message)
print("|---------------------------------|")
print(" Messages ")
print("|---------------------------------|")
chats = db.show_chat_messages()
for chat in chats:
print(" ",chat)
print("|--------------------------------------------------|")