Filter federated shared items

merge-requests/30/head
Bob Mottram 2021-07-28 22:28:41 +01:00
parent accd625b0a
commit 725ca29f5a
2 changed files with 20 additions and 6 deletions

View File

@ -119,14 +119,22 @@ def _isFilteredBase(filename: str, content: str) -> bool:
return False return False
def isFilteredGlobally(baseDir: str, content: str) -> bool:
"""Is the given content globally filtered?
"""
globalFiltersFilename = baseDir + '/accounts/filters.txt'
if _isFilteredBase(globalFiltersFilename, content):
return True
return False
def isFiltered(baseDir: str, nickname: str, domain: str, content: str) -> bool: def isFiltered(baseDir: str, nickname: str, domain: str, content: str) -> bool:
"""Should the given content be filtered out? """Should the given content be filtered out?
This is a simple type of filter which just matches words, not a regex This is a simple type of filter which just matches words, not a regex
You can add individual words or use word1+word2 to indicate that two You can add individual words or use word1+word2 to indicate that two
words must be present although not necessarily adjacent words must be present although not necessarily adjacent
""" """
globalFiltersFilename = baseDir + '/accounts/filters.txt' if isFilteredGlobally(baseDir, content):
if _isFilteredBase(globalFiltersFilename, content):
return True return True
if not nickname or not domain: if not nickname or not domain:

View File

@ -34,7 +34,7 @@ from utils import isAccountDir
from utils import acctDir from utils import acctDir
from utils import isfloat from utils import isfloat
from media import processMetaData from media import processMetaData
from filters import isFiltered from filters import isFilteredGlobally
def _loadDfcIds(baseDir: str, systemLanguage: str) -> {}: def _loadDfcIds(baseDir: str, systemLanguage: str) -> {}:
@ -240,7 +240,7 @@ def addShare(baseDir: str,
systemLanguage: str, translate: {}) -> None: systemLanguage: str, translate: {}) -> None:
"""Adds a new share """Adds a new share
""" """
if isFiltered(baseDir, nickname, domain, if isFilteredGlobally(baseDir,
displayName + ' ' + summary + ' ' + displayName + ' ' + summary + ' ' +
itemType + ' ' + itemCategory): itemType + ' ' + itemCategory):
print('Shared item was filtered due to content') print('Shared item was filtered due to content')
@ -1306,9 +1306,15 @@ def _dfcToSharesFormat(catalogJson: {},
itemCategory = 'food' itemCategory = 'food'
if not itemType: if not itemType:
continue continue
allText = item['DFC:description'] + ' ' + itemType + ' ' + itemCategory
if isFilteredGlobally(baseDir, allText):
continue
dfcId = dfcIds[itemType] dfcId = dfcIds[itemType]
itemID = item['@id'] itemID = item['@id']
description = item['DFC:description'].split(':', 1)[1].strip() description = item['DFC:description'].split(':', 1)[1].strip()
sharesJson[itemID] = { sharesJson[itemID] = {
"displayName": item['DFC:description'].split(':')[0], "displayName": item['DFC:description'].split(':')[0],
"summary": description, "summary": description,