-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook (1).py
78 lines (73 loc) · 3.75 KB
/
facebook (1).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
from Comment import *
from User import *
from Status import *
class Facebook:
#Facebook(dict-of-string:user,list-of-status,string)
def __init__(self):
self.facebookUser={}
self.facebookStatus=[]
self.currentlyUsing=""
def registerUser(self,name,email):
user1=User(name,email)
if name in self.facebookUser:
print("This username has already been taken")
else:
self.facebookUser[name]=user1
def login(self,name2):
if self.currentlyUsing!="":
print("Somebody has already logged into this account and that person needs to log out first")
else:
self.currentlyUsing=name2
def logout(self):
if self.currentlyUsing=="":
print("Noone is currently logged in")
else:
self.currentlyUsing=""
def addFriend(self,name):
if self.currentlyUsing=="":
print("Noone is currently logged in")
elif name not in self.facebookUser:
print("Cannot find anyone with the given username")
else:
friend1=self.facebookUser[self.currentlyUsing]
friend2=self.facebookUser[name]
friend1.addFriend(friend2)
def viewProfile(self):
currentlyUsingUser=self.facebookUser[self.currentlyUsing]
print (str(currentlyUsingUser))
def postStatus(self,theStatus):
if self.currentlyUsing=="":
print("Noone is currently logged in")
else:
status1=Status(self.currentlyUsing,theStatus,[],[])
self.facebookStatus.append(status1)
def viewStatus(self):
if self.currentlyUsing=="":
print("Noone is currently logged in ")
else:
viewStatusString=""
for i in range (len(self.facebookStatus)):
if self.facebookStatus[i].statusPoster==self.currentlyUsing or self.facebookUser[self.facebookStatus[i].statusPoster] in self.facebookUser[self.currentlyUsing].friends:
if len(self.facebookStatus)>1 and len(self.facebookUser[self.currentlyUsing].friends)>1:
viewStatusString=viewStatusString+"["+str(i)+"] "+str(self.facebookStatus[i])+"\n"
elif len(self.facebookStatus)==1 or len(self.facebookUser[self.currentlyUsing].friends)==1:
viewStatusString=viewStatusString+"["+str(i)+"] "+str(self.facebookStatus[i])
print (viewStatusString)
def likeStatus(self,IDnumber):
statusToLike=self.facebookStatus[IDnumber]
if self.currentlyUsing=="":
print("Noone is currently logged in ")
elif self.facebookUser[statusToLike.statusPoster]!=self.facebookUser[self.currentlyUsing]and self.facebookUser[statusToLike.statusPoster] not in self.facebookUser[self.currentlyUsing].friends:
print("You cannot like this status because it belongs to the user who is not your friend")
else:
statusToLike.statusLikers.append(self.currentlyUsing)
def commentOnStatus(self,IDnumber,theComment):
statusToComment=self.facebookStatus[IDnumber]
if self.currentlyUsing=="":
print("Noone is currently logged in ")
elif self.facebookUser[statusToComment.statusPoster]!=self.facebookUser[self.currentlyUsing]and self.facebookUser[statusToComment.statusPoster] not in self.facebookUser[self.currentlyUsing].friends:
print("You cannot comment in this status because it belongs to the user who is not your friend")
else:
Comment1=Comment(self.currentlyUsing,theComment)
statusToComment=self.facebookStatus[IDnumber]
statusToComment.comments.append(Comment1)