forked from indymedia/epicyon
Functions for counting followers on a domain
parent
8b285809c5
commit
410010ec2b
16
follow.py
16
follow.py
|
@ -36,6 +36,22 @@ def getFollowersOfPerson(baseDir: str,nickname: str,domain: str,followFile='foll
|
||||||
break
|
break
|
||||||
return followers
|
return followers
|
||||||
|
|
||||||
|
def noOfFollowersOnDomain(baseDir: str,handle: str, domain: str, followFile='followers.txt') -> int:
|
||||||
|
"""Returns the number of followers of the given handle from the given domain
|
||||||
|
"""
|
||||||
|
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
ctr=0
|
||||||
|
with open(filename, "r") as followersFilename:
|
||||||
|
for followerHandle in followersFilename:
|
||||||
|
if '@' in followerHandle:
|
||||||
|
followerDomain=followerHandle.split('@')[1].replace('\n','')
|
||||||
|
if domain==followerDomain:
|
||||||
|
ctr+=1
|
||||||
|
return ctr
|
||||||
|
|
||||||
def followPerson(baseDir: str,nickname: str, domain: str, \
|
def followPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
followNickname: str, followDomain: str, \
|
followNickname: str, followDomain: str, \
|
||||||
federationList: [], followFile='following.txt') -> bool:
|
federationList: [], followFile='following.txt') -> bool:
|
||||||
|
|
41
tests.py
41
tests.py
|
@ -30,6 +30,7 @@ from follow import followerOfPerson
|
||||||
from follow import unfollowPerson
|
from follow import unfollowPerson
|
||||||
from follow import unfollowerOfPerson
|
from follow import unfollowerOfPerson
|
||||||
from follow import getFollowersOfPerson
|
from follow import getFollowersOfPerson
|
||||||
|
from follow import noOfFollowersOnDomain
|
||||||
from person import createPerson
|
from person import createPerson
|
||||||
from person import setPreferredNickname
|
from person import setPreferredNickname
|
||||||
from person import setBio
|
from person import setBio
|
||||||
|
@ -271,7 +272,46 @@ def testFollowersOfPerson():
|
||||||
assert 'sausagedog@'+domain in followList
|
assert 'sausagedog@'+domain in followList
|
||||||
os.chdir(currDir)
|
os.chdir(currDir)
|
||||||
shutil.rmtree(baseDir)
|
shutil.rmtree(baseDir)
|
||||||
|
|
||||||
|
def testNoOfFollowersOnDomain():
|
||||||
|
print('testNoOfFollowersOnDomain')
|
||||||
|
currDir=os.getcwd()
|
||||||
|
nickname='mxpop'
|
||||||
|
domain='diva.domain'
|
||||||
|
otherdomain='soup.dragon'
|
||||||
|
password='birb'
|
||||||
|
port=80
|
||||||
|
httpPrefix='https'
|
||||||
|
federationList=[]
|
||||||
|
baseDir=currDir+'/.tests_nooffollowersOndomain'
|
||||||
|
if os.path.isdir(baseDir):
|
||||||
|
shutil.rmtree(baseDir)
|
||||||
|
os.mkdir(baseDir)
|
||||||
|
os.chdir(baseDir)
|
||||||
|
createPerson(baseDir,nickname,domain,port,httpPrefix,True,password)
|
||||||
|
createPerson(baseDir,'maxboardroom',otherdomain,port,httpPrefix,True,password)
|
||||||
|
createPerson(baseDir,'ultrapancake',otherdomain,port,httpPrefix,True,password)
|
||||||
|
createPerson(baseDir,'drokk',otherdomain,port,httpPrefix,True,password)
|
||||||
|
createPerson(baseDir,'sausagedog',otherdomain,port,httpPrefix,True,password)
|
||||||
|
|
||||||
|
followPerson(baseDir,'drokk',otherdomain,nickname,domain,federationList)
|
||||||
|
followPerson(baseDir,'sausagedog',otherdomain,nickname,domain,federationList)
|
||||||
|
followPerson(baseDir,'maxboardroom',otherdomain,nickname,domain,federationList)
|
||||||
|
|
||||||
|
followerOfPerson(baseDir,nickname,domain,'drokk',otherdomain,federationList)
|
||||||
|
followerOfPerson(baseDir,nickname,domain,'sausagedog',otherdomain,federationList)
|
||||||
|
followerOfPerson(baseDir,nickname,domain,'maxboardroom',otherdomain,federationList)
|
||||||
|
|
||||||
|
followersOnOtherDomain=noOfFollowersOnDomain(baseDir,nickname+'@'+domain, otherdomain)
|
||||||
|
assert followersOnOtherDomain==3
|
||||||
|
|
||||||
|
unfollowerOfPerson(baseDir,nickname,domain,'sausagedog',otherdomain)
|
||||||
|
followersOnOtherDomain=noOfFollowersOnDomain(baseDir,nickname+'@'+domain, otherdomain)
|
||||||
|
assert followersOnOtherDomain==2
|
||||||
|
|
||||||
|
os.chdir(currDir)
|
||||||
|
shutil.rmtree(baseDir)
|
||||||
|
|
||||||
def testFollows():
|
def testFollows():
|
||||||
print('testFollows')
|
print('testFollows')
|
||||||
currDir=os.getcwd()
|
currDir=os.getcwd()
|
||||||
|
@ -402,5 +442,6 @@ def runAllTests():
|
||||||
testCreatePerson()
|
testCreatePerson()
|
||||||
testAuthentication()
|
testAuthentication()
|
||||||
testFollowersOfPerson()
|
testFollowersOfPerson()
|
||||||
|
testNoOfFollowersOnDomain()
|
||||||
testFollows()
|
testFollows()
|
||||||
print('Tests succeeded\n')
|
print('Tests succeeded\n')
|
||||||
|
|
Loading…
Reference in New Issue