master
Bob Mottram 2019-07-02 20:05:59 +01:00
parent 4166ce5b70
commit 8276f24468
1 changed files with 28 additions and 13 deletions

View File

@ -13,7 +13,9 @@ import sys
from person import validUsername from person import validUsername
from utils import domainPermitted from utils import domainPermitted
def followPerson(baseDir: str,username: str, domain: str, followUsername: str, followDomain: str, federationList: [], followFile='following.txt') -> bool: def followPerson(baseDir: str,username: str, domain: str, \
followUsername: str, followDomain: str, \
federationList: [], followFile='following.txt') -> bool:
"""Adds a person to the follow list """Adds a person to the follow list
""" """
if not domainPermitted(followDomain.lower().replace('\n',''), federationList): if not domainPermitted(followDomain.lower().replace('\n',''), federationList):
@ -35,12 +37,18 @@ def followPerson(baseDir: str,username: str, domain: str, followUsername: str, f
followfile.write(handleToFollow+'\n') followfile.write(handleToFollow+'\n')
return True return True
def followerOfPerson(baseDir: str,username: str, domain: str, followerUsername: str, followerDomain: str, federationList: []) -> bool: def followerOfPerson(baseDir: str,username: str, domain: str, \
followerUsername: str, followerDomain: str, \
federationList: []) -> bool:
"""Adds a follower of the given person """Adds a follower of the given person
""" """
return followPerson(baseDir,username, domain, followerUsername, followerDomain, federationList, 'followers.txt') return followPerson(baseDir,username, domain, \
followerUsername, followerDomain, \
federationList, 'followers.txt')
def unfollowPerson(baseDir: str,username: str, domain: str, followUsername: str, followDomain: str,followFile='following.txt') -> None: def unfollowPerson(baseDir: str,username: str, domain: str, \
followUsername: str, followDomain: str, \
followFile='following.txt') -> None:
"""Removes a person to the follow list """Removes a person to the follow list
""" """
handle=username.lower()+'@'+domain.lower() handle=username.lower()+'@'+domain.lower()
@ -60,12 +68,13 @@ def unfollowPerson(baseDir: str,username: str, domain: str, followUsername: str,
if line.strip("\n") != handleToUnfollow: if line.strip("\n") != handleToUnfollow:
f.write(line) f.write(line)
def unfollowerOfPerson(username: str, domain: str, followerUsername: str, followerDomain: str) -> None: def unfollowerOfPerson(baseDir: str,username: str,domain: str, \
followerUsername: str,followerDomain: str) -> None:
"""Remove a follower of a person """Remove a follower of a person
""" """
unfollowPerson(username, domain, followerUsername, followerDomain,'followers.txt') unfollowPerson(baseDir,username,domain,followerUsername,followerDomain,'followers.txt')
def clearFollows(baseDir: str,username: str, domain: str,followFile='following.txt') -> None: def clearFollows(baseDir: str,username: str,domain: str,followFile='following.txt') -> None:
"""Removes all follows """Removes all follows
""" """
handle=username.lower()+'@'+domain.lower() handle=username.lower()+'@'+domain.lower()
@ -77,12 +86,12 @@ def clearFollows(baseDir: str,username: str, domain: str,followFile='following.t
if os.path.isfile(filename): if os.path.isfile(filename):
os.remove(filename) os.remove(filename)
def clearFollowers(baseDir: str,username: str, domain: str) -> None: def clearFollowers(baseDir: str,username: str,domain: str) -> None:
"""Removes all followers """Removes all followers
""" """
clearFollows(baseDir,username, domain,'followers.txt') clearFollows(baseDir,username, domain,'followers.txt')
def getNoOfFollows(baseDir: str,username: str,domain: str, followFile='following.txt') -> int: def getNoOfFollows(baseDir: str,username: str,domain: str,followFile='following.txt') -> int:
"""Returns the number of follows or followers """Returns the number of follows or followers
""" """
handle=username.lower()+'@'+domain.lower() handle=username.lower()+'@'+domain.lower()
@ -100,12 +109,13 @@ def getNoOfFollows(baseDir: str,username: str,domain: str, followFile='following
ctr += 1 ctr += 1
return ctr return ctr
def getNoOfFollowers(username: str,domain: str) -> int: def getNoOfFollowers(baseDir: str,username: str,domain: str) -> int:
"""Returns the number of followers of the given person """Returns the number of followers of the given person
""" """
return getNoOfFollows(username,domain,'followers.txt') return getNoOfFollows(baseDir,username,domain,'followers.txt')
def getFollowingFeed(baseDir: str,domain: str,port: int,path: str,https: bool,followsPerPage=12,followFile='following') -> {}: def getFollowingFeed(baseDir: str,domain: str,port: int,path: str,https: bool, \
followsPerPage=12,followFile='following') -> {}:
"""Returns the following and followers feeds from GET requests """Returns the following and followers feeds from GET requests
""" """
if '/'+followFile not in path: if '/'+followFile not in path:
@ -225,7 +235,11 @@ def receiveFollowRequest(baseDir: str,messageJson: {},federationList: []) -> boo
return False return False
return followerOfPerson(baseDir,username,domain,usernameToFollow,domainToFollow,federationList) return followerOfPerson(baseDir,username,domain,usernameToFollow,domainToFollow,federationList)
def sendFollowRequest(baseDir: str,username: str, domain: str, port: int,https: bool,followUsername: str, followDomain: str, followPort: bool,followHttps: bool,federationList: []): def sendFollowRequest(baseDir: str,username: str,domain: str,port: int,https: bool, \
followUsername: str,followDomain: str,followPort: bool,followHttps: bool, \
federationList: []):
"""Sends a follow request
"""
if not domainPermitted(followDomain,federationList): if not domainPermitted(followDomain,federationList):
return None return None
@ -250,6 +264,7 @@ def sendFollowRequest(baseDir: str,username: str, domain: str, port: int,https:
'to': [toUrl], 'to': [toUrl],
'cc': [] 'cc': []
} }
if ccUrl: if ccUrl:
if len(ccUrl)>0: if len(ccUrl)>0:
newFollow['cc']=ccUrl newFollow['cc']=ccUrl