from utils.httputil import Http
from utils.dbQry import MyDbUtil
http = Http()
mydb = MyDbUtil()
def query_interface():
list = mydb.select_some("systems", "switch", 1)
nodes = mydb.select_some("node", "switch", 1)
tasks = mydb.select_some("task", "switch", 1)
apis = mydb.select_some("apis", "switch", 1)
if list:
treelist = []
for node in list:
system = {"sys_id": node.get("id"), "sys_name": node.get("name"), "children": []}
treelist.append(system)
for tl in treelist:
if nodes:
for node in nodes:
if tl.get('sys_id') == node.get('systems_id'):
node2 = {"node_id": node.get("id"), "node_name": node.get("name"), "children": []}
if tasks:
for task in tasks:
if node.get("id") == task.get('node_id'):
node3 = {"task_id": task.get("id"), "task_name": task.get("name"),
"task_result": task.get("expected"),
"expression": eval(task.get("expression")),
"frequency": task.get("frequency"), "children": []}
node2['children'].append(node3)
if apis:
for api in apis:
if task.get("id") == api.get("task_id"):
node4 = {"api_id": api.get("id"), "api_name": api.get("name"),
"method": api.get("method"), "url": api.get("url"),
"params": api.get("params")}
node3['children'].append(node4)
tl['children'].append(node2)
return treelist
else:
return None
# rs = http.doHttp(method=interface.get("method"), url=interface.get("url"), data=json.dumps(interface.get("params")))
# print("CCC",rs)
if __name__:
rs = query_interface()