Move function location

master
Bob Mottram 2019-07-05 15:39:24 +01:00
parent 94d412a5aa
commit bec891c081
3 changed files with 23 additions and 17 deletions

View File

@ -36,22 +36,6 @@ 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:

View File

@ -35,6 +35,22 @@ try:
except ImportError: except ImportError:
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
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 getPersonKey(nickname: str,domain: str,baseDir: str,keyType='public'): def getPersonKey(nickname: str,domain: str,baseDir: str,keyType='public'):
"""Returns the public or private key of a person """Returns the public or private key of a person
""" """
@ -456,6 +472,12 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox = \ inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox = \
getPersonBox(session,wfRequest,personCache,'inbox') getPersonBox(session,wfRequest,personCache,'inbox')
# If there are more than one followers on the target domain
# then send to teh shared inbox indead of the individual inbox
if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox:
inboxUrl=sharedInbox
if not inboxUrl: if not inboxUrl:
return 2 return 2
if not pubKey: if not pubKey:

View File

@ -23,6 +23,7 @@ from posts import deleteAllPosts
from posts import createPublicPost from posts import createPublicPost
from posts import sendPost from posts import sendPost
from posts import archivePosts from posts import archivePosts
from posts import noOfFollowersOnDomain
from follow import clearFollows from follow import clearFollows
from follow import clearFollowers from follow import clearFollowers
from follow import followPerson from follow import followPerson
@ -30,7 +31,6 @@ 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