From 9ed20c111e1509d216cfd69e197a624a347b7fb6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 6 Oct 2019 10:48:37 +0100 Subject: [PATCH] Tidying --- follow.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/follow.py b/follow.py index eb1026fa..dff36b9e 100644 --- a/follow.py +++ b/follow.py @@ -26,28 +26,44 @@ from auth import createBasicAuthHeader from auth import createPassword from session import postJson -def removeFromFollowRequests(baseDir: str, \ - nickname: str,domain: str, \ - denyHandle: str): - """Removes a handle from follow requests +def removeFromFollowBase(baseDir: str, \ + nickname: str,domain: str, \ + acceptOrDenyHandle: str,followFile: str) -> None: + """Removes a handle from follow requests or rejects file """ handle=nickname+'@'+domain accountsDir=baseDir+'/accounts/'+handle - approveFollowsFilename=accountsDir+'/followrequests.txt' + approveFollowsFilename=accountsDir+'/'+followFile+'.txt' if not os.path.isfile(approveFollowsFilename): if debug: print('WARN: Follow requests file '+approveFollowsFilename+' not found') return - if denyHandle not in open(approveFollowsFilename).read(): + if acceptOrDenyHandle not in open(approveFollowsFilename).read(): return approvefilenew = open(approveFollowsFilename+'.new', 'w+') with open(approveFollowsFilename, 'r') as approvefile: for approveHandle in approvefile: - if not approveHandle.startswith(denyHandle): + if not approveHandle.startswith(acceptOrDenyHandle): approvefilenew.write(approveHandle) approvefilenew.close() os.rename(approveFollowsFilename+'.new',approveFollowsFilename) +def removeFromFollowRequests(baseDir: str, \ + nickname: str,domain: str, \ + denyHandle: str) -> None: + """Removes a handle from follow requests + """ + removeFromFollowBase(baseDir,nickname,domain, \ + denyHandle,'followrequests') + +def removeFromFollowRejects(baseDir: str, \ + nickname: str,domain: str, \ + acceptHandle: str) -> None: + """Removes a handle from follow rejects + """ + removeFromFollowBase(baseDir,nickname,domain, \ + acceptHandle,'followrejects') + def isFollowingActor(baseDir: str,nickname: str,domain: str,actor: str) -> bool: """Is the given actor a follower of the given nickname? """