From c9f3d21b4115ee01b7fb31d942e265b224c76060 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 20 Oct 2020 10:43:30 +0100 Subject: [PATCH] Support xor in hashtag rules --- newsdaemon.py | 17 ++++++++++++++++- tests.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/newsdaemon.py b/newsdaemon.py index 3b329759..91229b2f 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 6e06fd9a..0bc9ea0d 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 = \