Create a dictionary of blog posts to be moderated

main
Bob Mottram 2020-10-06 11:34:56 +01:00
parent 2d7e6f4f43
commit ebb760a3c3
2 changed files with 64 additions and 2 deletions

View File

@ -170,6 +170,56 @@ def getRSSfromDict(baseDir: str, newswire: {},
return rssStr return rssStr
def updateNewswireModerationQueue(baseDir: str, handle: str,
maxBlogsPerAccount: int,
moderationDict: {}) -> None:
"""Puts new blog posts by untrusted accounts into a moderation queue
"""
accountDir = os.path.join(baseDir + '/accounts', handle)
indexFilename = accountDir + '/tlblogs.index'
if not os.path.isfile(indexFilename):
return
nickname = handle.split('@')[0]
domain = handle.split('@')[1]
with open(indexFilename, 'r') as indexFile:
postFilename = 'start'
ctr = 0
while postFilename:
postFilename = indexFile.readline()
if postFilename:
# if this is a full path then remove the directories
if '/' in postFilename:
postFilename = postFilename.split('/')[-1]
# filename of the post without any extension or path
# This should also correspond to any index entry in
# the posts cache
postUrl = \
postFilename.replace('\n', '').replace('\r', '')
postUrl = postUrl.replace('.json', '').strip()
# read the post from file
fullPostFilename = \
locatePost(baseDir, nickname,
domain, postUrl, False)
moderationStatusFilename = fullPostFilename + '.moderate'
if not os.path.isfile(moderationStatusFilename):
statusFile = open(moderationStatusFilename, "w+")
if statusFile:
statusFile.write('[waiting]')
statusFile.close()
if '[accepted]' not in \
open(moderationStatusFilename).read():
if moderationDict.get(nickname):
moderationDict[nickname] = []
moderationDict[nickname].append(fullPostFilename)
ctr += 1
if ctr >= maxBlogsPerAccount:
break
def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str, def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str,
newswire: {}, newswire: {},
maxBlogsPerAccount: int, maxBlogsPerAccount: int,
@ -245,6 +295,8 @@ def addBlogsToNewswire(baseDir: str, newswire: {},
maxBlogsPerAccount: int) -> None: maxBlogsPerAccount: int) -> None:
"""Adds blogs from each user account into the newswire """Adds blogs from each user account into the newswire
""" """
moderationDict = {}
# go through each account # go through each account
for subdir, dirs, files in os.walk(baseDir + '/accounts'): for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for handle in dirs: for handle in dirs:
@ -252,14 +304,19 @@ def addBlogsToNewswire(baseDir: str, newswire: {},
continue continue
if 'inbox@' in handle: if 'inbox@' in handle:
continue continue
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
if not isTrustedByNewswire(baseDir, nickname):
continue
# has this account been suspended? # has this account been suspended?
if isSuspended(baseDir, nickname): if isSuspended(baseDir, nickname):
continue continue
# is this account trusted?
if not isTrustedByNewswire(baseDir, nickname):
updateNewswireModerationQueue(baseDir, handle, 5,
moderationDict)
continue
# is there a blogs timeline for this account? # is there a blogs timeline for this account?
accountDir = os.path.join(baseDir + '/accounts', handle) accountDir = os.path.join(baseDir + '/accounts', handle)
blogsIndex = accountDir + '/tlblogs.index' blogsIndex = accountDir + '/tlblogs.index'

View File

@ -633,6 +633,11 @@ def deletePost(baseDir: str, httpPrefix: str,
if os.path.isfile(muteFilename): if os.path.isfile(muteFilename):
os.remove(muteFilename) os.remove(muteFilename)
# remove any moderation file
moderationFilename = postFilename + '.moderate'
if os.path.isfile(moderationFilename):
os.remove(moderationFilename)
# remove cached html version of the post # remove cached html version of the post
cachedPostFilename = \ cachedPostFilename = \
getCachedPostFilename(baseDir, nickname, domain, postJsonObject) getCachedPostFilename(baseDir, nickname, domain, postJsonObject)