mirror of https://gitlab.com/bashrc2/epicyon
Filter federated shared items
parent
accd625b0a
commit
725ca29f5a
12
filters.py
12
filters.py
|
@ -119,14 +119,22 @@ def _isFilteredBase(filename: str, content: str) -> bool:
|
|||
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:
|
||||
"""Should the given content be filtered out?
|
||||
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
|
||||
words must be present although not necessarily adjacent
|
||||
"""
|
||||
globalFiltersFilename = baseDir + '/accounts/filters.txt'
|
||||
if _isFilteredBase(globalFiltersFilename, content):
|
||||
if isFilteredGlobally(baseDir, content):
|
||||
return True
|
||||
|
||||
if not nickname or not domain:
|
||||
|
|
14
shares.py
14
shares.py
|
@ -34,7 +34,7 @@ from utils import isAccountDir
|
|||
from utils import acctDir
|
||||
from utils import isfloat
|
||||
from media import processMetaData
|
||||
from filters import isFiltered
|
||||
from filters import isFilteredGlobally
|
||||
|
||||
|
||||
def _loadDfcIds(baseDir: str, systemLanguage: str) -> {}:
|
||||
|
@ -240,9 +240,9 @@ def addShare(baseDir: str,
|
|||
systemLanguage: str, translate: {}) -> None:
|
||||
"""Adds a new share
|
||||
"""
|
||||
if isFiltered(baseDir, nickname, domain,
|
||||
displayName + ' ' + summary + ' ' +
|
||||
itemType + ' ' + itemCategory):
|
||||
if isFilteredGlobally(baseDir,
|
||||
displayName + ' ' + summary + ' ' +
|
||||
itemType + ' ' + itemCategory):
|
||||
print('Shared item was filtered due to content')
|
||||
return
|
||||
sharesFilename = acctDir(baseDir, nickname, domain) + '/shares.json'
|
||||
|
@ -1306,9 +1306,15 @@ def _dfcToSharesFormat(catalogJson: {},
|
|||
itemCategory = 'food'
|
||||
if not itemType:
|
||||
continue
|
||||
|
||||
allText = item['DFC:description'] + ' ' + itemType + ' ' + itemCategory
|
||||
if isFilteredGlobally(baseDir, allText):
|
||||
continue
|
||||
|
||||
dfcId = dfcIds[itemType]
|
||||
itemID = item['@id']
|
||||
description = item['DFC:description'].split(':', 1)[1].strip()
|
||||
|
||||
sharesJson[itemID] = {
|
||||
"displayName": item['DFC:description'].split(':')[0],
|
||||
"summary": description,
|
||||
|
|
Loading…
Reference in New Issue