Apply hashtag moderation to news feeds

merge-requests/8/head
Bob Mottram 2020-10-17 15:23:35 +01:00
parent 18f8643725
commit 7835f02122
1 changed files with 19 additions and 9 deletions

View File

@ -18,6 +18,7 @@ from utils import saveJson
from utils import isSuspended from utils import isSuspended
from utils import containsInvalidChars from utils import containsInvalidChars
from blocking import isBlockedDomain from blocking import isBlockedDomain
from blocking import isBlockedHashtag
def rss2Header(httpPrefix: str, def rss2Header(httpPrefix: str,
@ -74,7 +75,7 @@ def getNewswireTags(text: str) -> []:
return tags return tags
def addNewswireDictEntry(newswire: {}, dateStr: str, def addNewswireDictEntry(baseDir: str, newswire: {}, dateStr: str,
title: str, link: str, title: str, link: str,
votesStatus: str, postFilename: str, votesStatus: str, postFilename: str,
description: str, moderated: bool, description: str, moderated: bool,
@ -83,6 +84,13 @@ def addNewswireDictEntry(newswire: {}, dateStr: str,
""" """
if not tags: if not tags:
tags = getNewswireTags(title + ' ' + description) tags = getNewswireTags(title + ' ' + description)
newswireItemBlocked = False
if tags:
for tag in tags:
if isBlockedHashtag(baseDir, tag):
newswireItemBlocked = True
break
if not newswireItemBlocked:
newswire[dateStr] = [title, link, newswire[dateStr] = [title, link,
votesStatus, postFilename, votesStatus, postFilename,
description, moderated, tags] description, moderated, tags]
@ -133,7 +141,7 @@ def xml2StrToDict(baseDir: str, xmlStr: str, moderated: bool,
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z") datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z")
postFilename = '' postFilename = ''
votesStatus = [] votesStatus = []
addNewswireDictEntry(result, str(publishedDate), addNewswireDictEntry(baseDir, result, str(publishedDate),
title, link, title, link,
votesStatus, postFilename, votesStatus, postFilename,
description, moderated) description, moderated)
@ -149,7 +157,8 @@ def xml2StrToDict(baseDir: str, xmlStr: str, moderated: bool,
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S UT") datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S UT")
postFilename = '' postFilename = ''
votesStatus = [] votesStatus = []
addNewswireDictEntry(result, str(publishedDate) + '+00:00', addNewswireDictEntry(baseDir, result,
str(publishedDate) + '+00:00',
title, link, title, link,
votesStatus, postFilename, votesStatus, postFilename,
description, moderated) description, moderated)
@ -208,7 +217,7 @@ def atomFeedToDict(baseDir: str, xmlStr: str, moderated: bool,
datetime.strptime(pubDate, "%Y-%m-%dT%H:%M:%SZ") datetime.strptime(pubDate, "%Y-%m-%dT%H:%M:%SZ")
postFilename = '' postFilename = ''
votesStatus = [] votesStatus = []
addNewswireDictEntry(result, str(publishedDate), addNewswireDictEntry(baseDir, result, str(publishedDate),
title, link, title, link,
votesStatus, postFilename, votesStatus, postFilename,
description, moderated) description, moderated)
@ -224,7 +233,8 @@ def atomFeedToDict(baseDir: str, xmlStr: str, moderated: bool,
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S UT") datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S UT")
postFilename = '' postFilename = ''
votesStatus = [] votesStatus = []
addNewswireDictEntry(result, str(publishedDate) + '+00:00', addNewswireDictEntry(baseDir, result,
str(publishedDate) + '+00:00',
title, link, title, link,
votesStatus, postFilename, votesStatus, postFilename,
description, moderated) description, moderated)
@ -427,7 +437,7 @@ def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str,
if os.path.isfile(fullPostFilename + '.votes'): if os.path.isfile(fullPostFilename + '.votes'):
votes = loadJson(fullPostFilename + '.votes') votes = loadJson(fullPostFilename + '.votes')
description = '' description = ''
addNewswireDictEntry(newswire, published, addNewswireDictEntry(baseDir, newswire, published,
postJsonObject['object']['summary'], postJsonObject['object']['summary'],
postJsonObject['object']['url'], postJsonObject['object']['url'],
votes, fullPostFilename, votes, fullPostFilename,