From 1655a68c7c65dbeae94f238032b7e2096e1801e7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 25 Sep 2020 13:46:06 +0100 Subject: [PATCH] Move function --- epicyon.py | 2 +- follow.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ posts.py | 56 ------------------------------------------------------ 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/epicyon.py b/epicyon.py index 670a87f0d..f2a9918ec 100644 --- a/epicyon.py +++ b/epicyon.py @@ -15,7 +15,6 @@ from person import deactivateAccount from skills import setSkillLevel from roles import setRole from webfinger import webfingerHandle -#from posts import checkDomains #from posts import getPublicPostDomains #from posts import getPublicPostDomainsBlocked from posts import sendBlockViaServer @@ -36,6 +35,7 @@ import sys import time from pprint import pprint from daemon import runDaemon +from follow import checkDomains from follow import clearFollows from follow import followerOfPerson from follow import sendFollowRequestViaServer diff --git a/follow.py b/follow.py index 2dd88048a..2d0534f30 100644 --- a/follow.py +++ b/follow.py @@ -25,6 +25,61 @@ from auth import createBasicAuthHeader from session import postJson +def checkDomains(session, baseDir: str, + nickname: str, domain: str, + proxyType: str, port: int, httpPrefix: str, + debug: bool, projectVersion: str, + maxBlockedDomains: int, singleCheck: bool): + """Checks follower accounts for references to globally blocked domains + """ + nonMutuals = getNonMutualsOfPerson(baseDir, nickname, domain) + if not nonMutuals: + return + followerWarningFilename = baseDir + '/accounts/followerWarnings.txt' + updateFollowerWarnings = False + followerWarningStr = '' + if os.path.isfile(followerWarningFilename): + with open(followerWarningFilename, 'r') as fp: + followerWarningStr = fp.read() + + if singleCheck: + # checks a single random non-mutual + index = random.randrange(0, len(nonMutuals)) + domainName = nonMutuals[index] + blockedDomains = \ + getPublicPostDomainsBlocked(session, baseDir, + nickname, domain, + proxyType, port, httpPrefix, + debug, projectVersion, []) + if blockedDomains: + if len(blockedDomains) > maxBlockedDomains: + followerWarningStr += domainName + '\n' + updateFollowerWarnings = True + else: + # checks all non-mutuals + for domainName in nonMutuals: + if domainName in followerWarningStr: + continue + blockedDomains = \ + getPublicPostDomainsBlocked(session, baseDir, + nickname, domain, + proxyType, port, httpPrefix, + debug, projectVersion, []) + if blockedDomains: + print(domainName) + for d in blockedDomains: + print(' ' + d) + if len(blockedDomains) > maxBlockedDomains: + followerWarningStr += domainName + '\n' + updateFollowerWarnings = True + + if updateFollowerWarnings and followerWarningStr: + with open(followerWarningFilename, 'w+') as fp: + fp.write(followerWarningStr) + if not singleCheck: + print(followerWarningStr) + + def preApprovedFollower(baseDir: str, nickname: str, domain: str, approveHandle: str) -> bool: diff --git a/posts.py b/posts.py index ee7b8ccd4..e98d21e83 100644 --- a/posts.py +++ b/posts.py @@ -60,7 +60,6 @@ from filters import isFiltered from git import convertPostToPatch from jsonldsig import jsonldSign from petnames import resolvePetnames -from follow import getNonMutualsOfPerson # try: # from BeautifulSoup import BeautifulSoup # except ImportError: @@ -3332,61 +3331,6 @@ def getPublicPostDomainsBlocked(session, baseDir: str, return blockedDomains -def checkDomains(session, baseDir: str, - nickname: str, domain: str, - proxyType: str, port: int, httpPrefix: str, - debug: bool, projectVersion: str, - maxBlockedDomains: int, singleCheck: bool): - """Checks follower accounts for references to globally blocked domains - """ - nonMutuals = getNonMutualsOfPerson(baseDir, nickname, domain) - if not nonMutuals: - return - followerWarningFilename = baseDir + '/accounts/followerWarnings.txt' - updateFollowerWarnings = False - followerWarningStr = '' - if os.path.isfile(followerWarningFilename): - with open(followerWarningFilename, 'r') as fp: - followerWarningStr = fp.read() - - if singleCheck: - # checks a single random non-mutual - index = random.randrange(0, len(nonMutuals)) - domainName = nonMutuals[index] - blockedDomains = \ - getPublicPostDomainsBlocked(session, baseDir, - nickname, domain, - proxyType, port, httpPrefix, - debug, projectVersion, []) - if blockedDomains: - if len(blockedDomains) > maxBlockedDomains: - followerWarningStr += domainName + '\n' - updateFollowerWarnings = True - else: - # checks all non-mutuals - for domainName in nonMutuals: - if domainName in followerWarningStr: - continue - blockedDomains = \ - getPublicPostDomainsBlocked(session, baseDir, - nickname, domain, - proxyType, port, httpPrefix, - debug, projectVersion, []) - if blockedDomains: - print(domainName) - for d in blockedDomains: - print(' ' + d) - if len(blockedDomains) > maxBlockedDomains: - followerWarningStr += domainName + '\n' - updateFollowerWarnings = True - - if updateFollowerWarnings and followerWarningStr: - with open(followerWarningFilename, 'w+') as fp: - fp.write(followerWarningStr) - if not singleCheck: - print(followerWarningStr) - - def sendCapabilitiesUpdate(session, baseDir: str, httpPrefix: str, nickname: str, domain: str, port: int, followerUrl, updateCaps: [],