diff --git a/newsdaemon.py b/newsdaemon.py index 3b3297590..91229b2fe 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -136,6 +136,21 @@ def hashtagRuleResolve(tree: [], hashtags: [], moderated: bool, if argValue: return True 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: return tree[0] in hashtags elif tree[0].startswith('moderated'): @@ -239,7 +254,7 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {}, content = content.lower() # actionOccurred = False - operators = ('not', 'and', 'or', 'contains') + operators = ('not', 'and', 'or', 'xor', 'contains') for ruleStr in rules: if not ruleStr: continue diff --git a/tests.py b/tests.py index 6e06fd9ab..0bc9ea0dc 100644 --- a/tests.py +++ b/tests.py @@ -2177,7 +2177,7 @@ def testRemoveHtmlTag(): def testHashtagRuleTree(): print('testHashtagRuleTree') - operators = ('not', 'and', 'or', 'contains') + operators = ('not', 'and', 'or', 'xor', 'contains') moderated = True conditionsStr = \