mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Flows work + #302
This commit is contained in:
31
pialert/flows.py
Normal file
31
pialert/flows.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
|
||||
def update_value(json_data, object_path, key, value, target_property, desired_value):
|
||||
# Helper function to traverse the JSON structure and get the target object
|
||||
def traverse(obj, path):
|
||||
keys = path.split(".")
|
||||
for key in keys:
|
||||
if isinstance(obj, list):
|
||||
key = int(key)
|
||||
obj = obj[key]
|
||||
return obj
|
||||
|
||||
# Helper function to update the target property with the desired value
|
||||
def update(obj, path, key, value, target_property, desired_value):
|
||||
keys = path.split(".")
|
||||
for i, key in enumerate(keys):
|
||||
if isinstance(obj, list):
|
||||
key = int(key)
|
||||
# Check if we have reached the desired object
|
||||
if i == len(keys) - 1 and obj[key][key] == value:
|
||||
# Update the target property with the desired value
|
||||
obj[key][target_property] = desired_value
|
||||
else:
|
||||
obj = obj[key]
|
||||
return obj
|
||||
|
||||
# Get the target object based on the object path
|
||||
target_obj = traverse(json_data, object_path)
|
||||
# Update the value in the target object
|
||||
updated_obj = update(json_data, object_path, key, value, target_property, desired_value)
|
||||
return updated_obj
|
||||
Reference in New Issue
Block a user