Further implementation of forloops.. kinda

This commit is contained in:
frikky
2020-05-20 19:57:22 +02:00
parent c557d232c9
commit 063faf0f18
3 changed files with 130 additions and 68 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -53,7 +53,7 @@ if __name__ == "__main__":
"authorization": "hey", "authorization": "hey",
} }
apikey = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjYwZjQwNjBlNThkNzVmZDNmNzBiZWZmODhjNzk0YTc3NTMyN2FhMzEiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL3NodWZmbGVyLmlvL2FwaS92MS93b3JrZmxvd3MvMWQ5ZDhjZTItNTY2ZS00YzNmLThhMzctNWQ2YzdkMjAwMGI1L2V4ZWN1dGUiLCJhenAiOiIxMDMwNzY3ODIwNjE0MjQ2MTg0MjIiLCJlbWFpbCI6InNjaGVkdWxlckBzaHVmZmxlLTI0MTUxNy5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJleHAiOjE1NjU1Mjc1NTEsImlhdCI6MTU2NTUyMzk1MSwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tIiwic3ViIjoiMTAzMDc2NzgyMDYxNDI0NjE4NDIyIn0.r0EDq9fjhf_5CPTiltyfk_L3uYJp577Uy0yYPcCAl2nv50_z_oUtbWGBpQLL8gcj-NGd3g4E52Qur8k6hCMIQweLS6WAb1279vGffEoCNDfkWb3Oy-yJGP1kzwLvqFJqnHLkSWYXNWvSyWnEimW8Rryx_m1BXS5wcA8l4NIr83kS7fPZrTwjnwFSeGSThwk91DVARzapQb8r0GEgOUyHZ1aBXnV98mikzSUt-5xFKe9eMdD22YJAj0Ru-DxAxs5nOqghX4PMRysWjshjOMrlR1piPWxqAmewp8YKZDCQ5gXskpeAFBDoULT971Wsx_NCohnJsFqx1JfPS9ZYMTW2oQ" apikey = ""
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": f"Bearer {apikey}" "Authorization": f"Bearer {apikey}"
+64 -22
View File
@@ -109,10 +109,9 @@ class AppBase:
# Takes a workflow execution as argument # Takes a workflow execution as argument
# Returns a string if the result is single, or a list if it's a list # Returns a string if the result is single, or a list if it's a list
# Not implemented: lists
def get_json_value(execution_data, input_data): def get_json_value(execution_data, input_data):
parsersplit = input_data.split(".") parsersplit = input_data.split(".")
actionname = parsersplit[0][1:] actionname = parsersplit[0][1:].replace(" ", "_", -1)
print(f"Actionname: {actionname}") print(f"Actionname: {actionname}")
# 1. Find the action # 1. Find the action
@@ -122,14 +121,14 @@ class AppBase:
baseresult = execution_data["execution_argument"] baseresult = execution_data["execution_argument"]
else: else:
for result in execution_data["results"]: for result in execution_data["results"]:
resultlabel = result["action"]["label"].replace(" ", "_", -1) resultlabel = result["action"]["label"].replace(" ", "_", -1).lower()
if resultlabel.lower() == actionname.lower(): if resultlabel.lower() == actionname.lower():
baseresult = result["result"] baseresult = result["result"]
break break
except KeyError as error: except KeyError as error:
print(f"Error: {error}") print(f"Error: {error}")
print(f"After first trycatch") print(f"After first trycatch")
# 2. Find the JSON data # 2. Find the JSON data
@@ -145,19 +144,24 @@ class AppBase:
basejson = json.loads(baseresult) basejson = json.loads(baseresult)
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
return baseresult return baseresult
def loop_recursion(data):
for value in data:
pass
try: try:
cnt = 0
for value in parsersplit[1:]: for value in parsersplit[1:]:
print("VALUE: %s", value) cnt += 1
if value == "#": if value == "#":
print("HANDLE RECURSIVE LOOP") # FIXME - not recursive - should go deeper if there are more #
pass print("HANDLE RECURSIVE LOOP ")
returnlist = []
for innervalue in basejson:
#print("Value: %s" % value[parsersplit[cnt+1]])
returnlist.append(innervalue[parsersplit[cnt+1]])
# Example format: ${[]}$
return "${%s%s}$" % (parsersplit[cnt+1], json.dumps(returnlist))
else: else:
print("BASE: ", basejson)
if isinstance(basejson[value], str): if isinstance(basejson[value], str):
print(f"LOADING STRING '%s' AS JSON" % basejson[value]) print(f"LOADING STRING '%s' AS JSON" % basejson[value])
try: try:
@@ -167,12 +171,11 @@ class AppBase:
return basejson[value] return basejson[value]
else: else:
basejson = basejson[value] basejson = basejson[value]
except KeyError as e: except KeyError as e:
print(f"Keyerror: {e}") return "KeyError: %s" % e
return basejson
except IndexError as e: except IndexError as e:
print(f"Indexerror: {e}") return "IndexError: %s" % e
return basejson
return basejson return basejson
@@ -200,8 +203,6 @@ class AppBase:
elif isinstance(value, dict): elif isinstance(value, dict):
parameter["value"] = parameter["value"].replace(to_be_replaced, json.dumps(value)) parameter["value"] = parameter["value"].replace(to_be_replaced, json.dumps(value))
# Check if json inside string
#self.logger.info(f"CONVERT DATA FROM {parameter['value']} to {data}") #self.logger.info(f"CONVERT DATA FROM {parameter['value']} to {data}")
#parameter["value"] = data #parameter["value"] = data
@@ -459,17 +460,58 @@ class AppBase:
paramiter = [] paramiter = []
all_executions = [] all_executions = []
multiexecution = False
for parameter in action["parameters"]: for parameter in action["parameters"]:
check, value = parse_params(action, fullexecution, parameter) check, value = parse_params(action, fullexecution, parameter)
if check: if check:
raise Exception(check) raise Exception(check)
if isinstance(value, list): # Custom format for ${name[0,1]}$
params[parameter["name"]] = value submatch = "([${]{2}([0-9a-zA-Z_-]+)(\[.*\])[}$]{2})"
actualitem = re.findall(submatch, value, re.MULTILINE)
if len(actualitem) > 0:
multiexecution = True
# 1. Find the length of the longest array
# 2. Build an array with the base values based on parameter["value"]
# 3. Get the n'th value of the generated list from values
# 4. Execute all n answers
replacements = {}
for replace in actualitem:
try:
to_be_replaced = replace[0]
actualitem = replace[2]
except IndexError:
continue
itemlist = json.loads(actualitem)
if len(itemlist) > minlength:
minlength = len(itemlist)
replacements[to_be_replaced] = actualitem
resultarray = []
for i in range(0, minlength):
tmpitem = json.loads(json.dumps(parameter["value"]))
for key, value in replacements.items():
replacement = json.loads(value)[i]
tmpitem = tmpitem.replace(key, replacement, -1)
resultarray.append(tmpitem)
# With this parameter ready, add it to... a greater list of parameters. Rofl
print(resultarray[0])
else:
params[parameter["name"]] = value
# FIXME - this is horrible, but works for now # FIXME - this is horrible, but works for now
#for i in range(calltimes): #for i in range(calltimes):
result += await func(**params) if not multiexecution:
result += await func(**params)
else:
print("SHOULD RUN MULTI EXECUTION")
action_result["status"] = "SUCCESS" action_result["status"] = "SUCCESS"
action_result["result"] = str(result) action_result["result"] = str(result)