33 lines
904 B
Python
33 lines
904 B
Python
import json
|
|
|
|
def buildOutput(response, action, outputs):
|
|
if hasattr(action, "outputs"):
|
|
if response is not None:
|
|
try:
|
|
response_data = response.json()
|
|
except AttributeError:
|
|
response_data = json.loads(response)
|
|
response_objects = [response_data]
|
|
|
|
while response_objects:
|
|
response_object = response_objects.pop()
|
|
|
|
for key, value, in response_object.items():
|
|
|
|
if isinstance(value, dict):
|
|
response_objects.append(value)
|
|
|
|
for output_name, response_key in action.outputs.items():
|
|
if key == response_key:
|
|
outputs[output_name] = value
|
|
#print (response_data)
|
|
|
|
else:
|
|
print("No response received"),
|
|
|
|
|
|
|
|
return outputs
|
|
|
|
|