forked from indymedia/epicyon
Support xor in hashtag rules
parent
ddadcf1f8b
commit
c9f3d21b41
|
@ -136,6 +136,21 @@ def hashtagRuleResolve(tree: [], hashtags: [], moderated: bool,
|
||||||
if argValue:
|
if argValue:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
elif tree[0] == 'xor':
|
||||||
|
if len(tree) >= 3:
|
||||||
|
trueCtr = 0
|
||||||
|
for argIndex in range(1, len(tree)):
|
||||||
|
argValue = False
|
||||||
|
if isinstance(tree[argIndex], str):
|
||||||
|
argValue = (tree[argIndex] in hashtags)
|
||||||
|
elif isinstance(tree[argIndex], list):
|
||||||
|
argValue = hashtagRuleResolve(tree[argIndex],
|
||||||
|
hashtags, moderated,
|
||||||
|
content)
|
||||||
|
if argValue:
|
||||||
|
trueCtr += 1
|
||||||
|
if trueCtr == 1:
|
||||||
|
return True
|
||||||
elif tree[0].startswith('#') and len(tree) == 1:
|
elif tree[0].startswith('#') and len(tree) == 1:
|
||||||
return tree[0] in hashtags
|
return tree[0] in hashtags
|
||||||
elif tree[0].startswith('moderated'):
|
elif tree[0].startswith('moderated'):
|
||||||
|
@ -239,7 +254,7 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
|
||||||
content = content.lower()
|
content = content.lower()
|
||||||
|
|
||||||
# actionOccurred = False
|
# actionOccurred = False
|
||||||
operators = ('not', 'and', 'or', 'contains')
|
operators = ('not', 'and', 'or', 'xor', 'contains')
|
||||||
for ruleStr in rules:
|
for ruleStr in rules:
|
||||||
if not ruleStr:
|
if not ruleStr:
|
||||||
continue
|
continue
|
||||||
|
|
2
tests.py
2
tests.py
|
@ -2177,7 +2177,7 @@ def testRemoveHtmlTag():
|
||||||
|
|
||||||
def testHashtagRuleTree():
|
def testHashtagRuleTree():
|
||||||
print('testHashtagRuleTree')
|
print('testHashtagRuleTree')
|
||||||
operators = ('not', 'and', 'or', 'contains')
|
operators = ('not', 'and', 'or', 'xor', 'contains')
|
||||||
|
|
||||||
moderated = True
|
moderated = True
|
||||||
conditionsStr = \
|
conditionsStr = \
|
||||||
|
|
Loading…
Reference in New Issue