flake8 format

main
Bob Mottram 2020-04-03 10:11:54 +00:00
parent 654c5104d5
commit a9ee0fc1b2
1 changed files with 33 additions and 25 deletions

View File

@ -8,10 +8,12 @@ __status__="Production"
import os
def addFilter(baseDir: str, nickname: str, domain: str, words: str) -> bool:
"""Adds a filter for particular words within the content of a incoming posts
"""
filtersFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/filters.txt'
filtersFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read():
return False
@ -20,11 +22,13 @@ def addFilter(baseDir: str,nickname: str,domain: str,words: str) -> bool:
filtersFile.close()
return True
def removeFilter(baseDir: str,nickname: str,domain: str, \
def removeFilter(baseDir: str, nickname: str, domain: str,
words: str) -> bool:
"""Removes a word filter
"""
filtersFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/filters.txt'
filtersFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read():
with open(filtersFilename, 'r') as fp:
@ -38,6 +42,7 @@ def removeFilter(baseDir: str,nickname: str,domain: str, \
return True
return False
def isTwitterPost(content: str) -> bool:
"""Returns true if the given post content is a retweet or twitter crosspost
"""
@ -47,6 +52,7 @@ def isTwitterPost(content: str) -> bool:
return True
return False
def isFiltered(baseDir: str, nickname: str, domain: str, content: str) -> bool:
"""Should the given content be filtered out?
This is a simple type of filter which just matches words, not a regex
@ -54,12 +60,14 @@ def isFiltered(baseDir: str,nickname: str,domain: str,content: str) -> bool:
words must be present although not necessarily adjacent
"""
# optionally remove retweets
removeTwitter=baseDir+'/accounts/'+nickname+'@'+domain+'/.removeTwitter'
removeTwitter = baseDir + '/accounts/' + \
nickname + '@' + domain + '/.removeTwitter'
if os.path.isfile(removeTwitter):
if isTwitterPost(content):
return True
filtersFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/filters.txt'
filtersFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filtersFilename):
with open(filtersFilename, 'r') as fp:
for line in fp:
@ -70,7 +78,7 @@ def isFiltered(baseDir: str,nickname: str,domain: str,content: str) -> bool:
else:
filterWords = filterStr.replace('"', '').split('+')
for word in filterWords:
if not word in content:
if word not in content:
return False
return True
return False