mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-11 18:45:34 +00:00
Logic fix
This commit is contained in:
@@ -55,7 +55,7 @@ def filter_complete_rules(ruleset):
|
|||||||
]
|
]
|
||||||
return rules
|
return rules
|
||||||
|
|
||||||
def convert_to_jsonlogic(rule_dict: list):
|
def convert_to_jsonlogic(logic_operator: str, rule_dict: list):
|
||||||
"""
|
"""
|
||||||
Convert a structured rule dict into a JSON Logic rule.
|
Convert a structured rule dict into a JSON Logic rule.
|
||||||
|
|
||||||
@@ -64,9 +64,6 @@ def convert_to_jsonlogic(rule_dict: list):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Determine the logical operator ("ALL" -> "and", "ANY" -> "or")
|
|
||||||
logic_operator = "and" if rule_dict.get("conditions_match_logic", "ALL") == "ALL" else "or"
|
|
||||||
|
|
||||||
json_logic_conditions = []
|
json_logic_conditions = []
|
||||||
|
|
||||||
for condition in rule_dict:
|
for condition in rule_dict:
|
||||||
@@ -115,6 +112,7 @@ def execute_ruleset_against_all_plugins(current_watch_uuid: str, application_dat
|
|||||||
ruleset_settings = application_datastruct['watching'].get(current_watch_uuid)
|
ruleset_settings = application_datastruct['watching'].get(current_watch_uuid)
|
||||||
|
|
||||||
if ruleset_settings.get("conditions"):
|
if ruleset_settings.get("conditions"):
|
||||||
|
logic_operator = "and" if ruleset_settings.get("conditions_match_logic", "ALL") == "ALL" else "or"
|
||||||
complete_rules = filter_complete_rules(ruleset_settings['conditions'])
|
complete_rules = filter_complete_rules(ruleset_settings['conditions'])
|
||||||
if complete_rules:
|
if complete_rules:
|
||||||
# Give all plugins a chance to update the data dict again (that we will test the conditions against)
|
# Give all plugins a chance to update the data dict again (that we will test the conditions against)
|
||||||
@@ -126,8 +124,10 @@ def execute_ruleset_against_all_plugins(current_watch_uuid: str, application_dat
|
|||||||
if new_execute_data and isinstance(new_execute_data, dict):
|
if new_execute_data and isinstance(new_execute_data, dict):
|
||||||
EXECUTE_DATA.update(new_execute_data)
|
EXECUTE_DATA.update(new_execute_data)
|
||||||
|
|
||||||
ruleset = convert_to_jsonlogic(rule_dict=complete_rules)
|
ruleset = convert_to_jsonlogic(logic_operator=logic_operator, rule_dict=complete_rules)
|
||||||
result = jsonLogic(logic=ruleset, data=EXECUTE_DATA)
|
|
||||||
|
if not jsonLogic(logic=ruleset, data=EXECUTE_DATA):
|
||||||
|
result = False
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -40,12 +40,13 @@ def add_data(current_watch_uuid, application_datastruct, ephemeral_data):
|
|||||||
|
|
||||||
res = {}
|
res = {}
|
||||||
if 'text' in ephemeral_data:
|
if 'text' in ephemeral_data:
|
||||||
res['page_text'] = ephemeral_data['text']
|
res['page_filtered_text'] = ephemeral_data['text']
|
||||||
|
|
||||||
# Better to not wrap this in try/except so that the UI can see any errors
|
# Better to not wrap this in try/except so that the UI can see any errors
|
||||||
price = Price.fromstring(ephemeral_data.get('text'))
|
price = Price.fromstring(ephemeral_data.get('text'))
|
||||||
if price and price.amount != None:
|
if price and price.amount != None:
|
||||||
|
# This is slightly misleading, it's extracting a PRICE not a Number..
|
||||||
res['extracted_number'] = float(price.amount)
|
res['extracted_number'] = float(price.amount)
|
||||||
logger.debug(f"Extracted price result: '{price}' - returning float({res['extracted_number']})")
|
logger.debug(f"Extracted number result: '{price}' - returning float({res['extracted_number']})")
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user