From b1672fb9d56dc1f0d5e2d280d0a9cede67bfa950 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 25 Sep 2020 15:14:59 +0100 Subject: [PATCH] Return lists --- follow.py | 6 +++--- posts.py | 6 +++--- utils.py | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/follow.py b/follow.py index f717e77a..f641e916 100644 --- a/follow.py +++ b/follow.py @@ -8,7 +8,7 @@ __status__ = "Production" from pprint import pprint import os -from utils import getFollowersOfPerson +from utils import getFollowersList from utils import validNickname from utils import domainPermitted from utils import getDomainFromActor @@ -118,9 +118,9 @@ def getMutualsOfPerson(baseDir: str, i.e. accounts which they follow and which also follow back """ followers = \ - getFollowersOfPerson(baseDir, nickname, domain, 'followers.txt') + getFollowersList(baseDir, nickname, domain, 'followers.txt') following = \ - getFollowersOfPerson(baseDir, nickname, domain, 'following.txt') + getFollowersList(baseDir, nickname, domain, 'following.txt') mutuals = [] for handle in following: if handle in followers: diff --git a/posts.py b/posts.py index 32709891..3044d015 100644 --- a/posts.py +++ b/posts.py @@ -30,7 +30,7 @@ from session import postJsonString from session import postImage from webfinger import webfingerHandle from httpsig import createSignedHeader -from utils import getFollowersOfPerson +from utils import getFollowersList from utils import isEvil from utils import removeIdEnding from utils import siteIsActive @@ -3338,9 +3338,9 @@ def getNonMutualsOfPerson(baseDir: str, i.e. accounts which follow you but you don't follow them """ followers = \ - getFollowersOfPerson(baseDir, nickname, domain, 'followers.txt') + getFollowersList(baseDir, nickname, domain, 'followers.txt') following = \ - getFollowersOfPerson(baseDir, nickname, domain, 'following.txt') + getFollowersList(baseDir, nickname, domain, 'following.txt') nonMutuals = [] for handle in following: if handle not in followers: diff --git a/utils.py b/utils.py index 2be770b0..014c5bc2 100644 --- a/utils.py +++ b/utils.py @@ -19,6 +19,25 @@ from calendar import monthrange from followingCalendar import addPersonToCalendar +def getFollowersList(baseDir: str, + nickname: str, domain: str, + followFile='following.txt') -> []: + """Returns a list of followers for the given account + """ + filename = \ + baseDir + '/accounts/' + nickname + '@' + domain + '/' + followFile + + if not os.path.isfile(filename): + return [] + + with open(filename, "r") as f: + lines = f.readlines() + for i in range(len(lines)): + lines[i] = lines[i].strip() + return lines + return [] + + def getFollowersOfPerson(baseDir: str, nickname: str, domain: str, followFile='following.txt') -> []: