133 lines
5.0 KiB
Python
133 lines
5.0 KiB
Python
def buildSelect(response, action, outputs):
|
|
#if hasattr(action, "select"):
|
|
|
|
response_data = response.json()
|
|
#selection = action.select
|
|
#print(response_data)
|
|
|
|
select_data ={}
|
|
for item, index in action.select.items():
|
|
select_data[item] = response_data[item][index]
|
|
|
|
print(select_data)
|
|
|
|
#if select_data == None:
|
|
# selection = "not applied"
|
|
#else:
|
|
selection = select_data
|
|
|
|
return selection, action, outputs
|
|
|
|
|
|
def buildSelect2(action, outputs):
|
|
#print(outputs)
|
|
select_data = []
|
|
target = outputs[action.select["source"]]
|
|
selectmethod = action.select["selectmethod"]
|
|
targetkey = action.select["key"]
|
|
targetvalue = action.select["value"]
|
|
|
|
if isinstance(targetvalue, dict):
|
|
for resolvekey, resolveval in targetvalue.items():
|
|
print(resolvekey)
|
|
print(resolveval)
|
|
#outputtarget = outputs[resolvekey]
|
|
#for thing in resolveval:
|
|
outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
|
|
print (outputtarget)
|
|
targetvalue = outputtarget
|
|
#for item in target:
|
|
for item in target:
|
|
#print (item)
|
|
for key, value in item.items():
|
|
#if isinstance(targetvalue, dict):
|
|
#for resolvekey, resolveval in targetvalue.items():
|
|
#print(resolvekey)
|
|
#print(resolveval)
|
|
#outputtarget = outputs[resolvekey]
|
|
#for thing in resolveval:
|
|
#outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
|
|
#print (outputtarget)
|
|
#outputtarget = targetvalue
|
|
if selectmethod == "exclude":
|
|
if targetkey == key and item[key] != targetvalue:
|
|
select_data.append(item)
|
|
#print(item)
|
|
if selectmethod == "include":
|
|
if targetkey == key and item[key] == targetvalue:
|
|
select_data.append(item)
|
|
#print(item)
|
|
outputs[action.select["source"]] = select_data
|
|
#print(outputs)
|
|
return select_data, action, outputs
|
|
#for item in outputs[output_name]:
|
|
#for key, value in action.select.include.items():
|
|
#if key in item and item[key] == value:
|
|
#select_data.append(item)
|
|
|
|
def buildSelect3(action, outputs):
|
|
#print(outputs)
|
|
select_data = []
|
|
target = outputs[action.select["source"]]
|
|
#selectmethod = action.select["selectmethod"]
|
|
includekey = action.select["include"]["key"]
|
|
includevalue = action.select["include"]["value"]
|
|
excludekey = action.select["exclude"]["key"]
|
|
excludevalue = action.select["exclude"]["value"]
|
|
#if isinstance(targetvalue, dict):
|
|
#for resolvekey, resolveval in targetvalue.items():
|
|
#print(resolvekey)
|
|
#print(resolveval)
|
|
#outputtarget = outputs[resolvekey]
|
|
#for thing in resolveval:
|
|
#outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
|
|
#print (outputtarget)
|
|
#targetvalue = outputtarget
|
|
#for item in target:
|
|
#include_match = True
|
|
#exclude_match = True
|
|
|
|
for item in target:
|
|
include_match = True
|
|
exclude_match = True
|
|
|
|
if includekey:
|
|
include_match = item[includekey] == includevalue
|
|
|
|
if excludekey:
|
|
exclude_match = item[excludekey] != excludevalue
|
|
|
|
if include_match and exclude_match:
|
|
select_data.append(item)
|
|
#print (item)
|
|
#for key, value in item.items():
|
|
#if isinstance(targetvalue, dict):
|
|
#for resolvekey, resolveval in targetvalue.items():
|
|
#print(resolvekey)
|
|
#print(resolveval)
|
|
#outputtarget = outputs[resolvekey]
|
|
#for thing in resolveval:
|
|
#outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
|
|
#print (outputtarget)
|
|
#outputtarget = targetvalue
|
|
#if selectmethod == "exclude":
|
|
#if item[excludekey] != excludevalue:# and item[includekey] == includevalue:
|
|
#if includekey == key and item[key] == includevalue:
|
|
#if item[excludekey] == excludevalue:
|
|
#continue
|
|
#select_data.append(item)
|
|
#if item[includekey] == includevalue:
|
|
#if includekey == key and item[key] == includevalue:
|
|
#continue
|
|
#select_data.append(item)
|
|
#if excludekey == key and item[key] != excludevalue:
|
|
#select_data.append(item)
|
|
#print(item)
|
|
#if selectmethod == "include":
|
|
#if excludekey == key and item[key] == excludevalue:
|
|
#select_data.append(item)
|
|
#print(item)
|
|
outputs[action.select["source"]] = select_data
|
|
print(select_data)
|
|
return select_data, action, outputs
|