def data_from_db(query): rows = select_query(query) rowarray_list = [] rowarray_list = [] for row in rows: d = dict(zip(row.keys(), row)) rowarray_list.append(d) json_data = rowarray_list data = json_data[0] return data
def getreport(scan_id): sid = scan_id query = "SELECT * FROM `DataDB` WHERE `ScanId` = '%s'" % sid rows = select_query(query) rowarray_list = [] for row in rows: d = dict(zip(row.keys(), row)) # a dict with column names as keys rowarray_list.append(d) # json_data = json.dumps(rowarray_list) # data = json.loads(json_data) # data = rowarray_list[0] json_data = rowarray_list data = json_data[0] print(data) null_key_list = [] for key, value in data.items(): val_list = eval(value) if not val_list: # print(key) null_key_list.append(key) # removing all unused components for key in null_key_list: del data[key] response = {} for key, value in data.items(): val_list = eval(value) if key == 'Activity': response.__setitem__(key, val_list) if key == 'ExportedActivity': response.__setitem__(key, val_list) if key == 'BroadcastReceiver': response.__setitem__(key, val_list) if key == 'ExportedReceiver': response.__setitem__(key, val_list) if key == 'Permission': response.__setitem__(key, val_list) if key == 'CriticalPerm': response.__setitem__(key, val_list) if key == 'CustomPerm': response.__setitem__(key, val_list) if key == 'Deeplinks': response.__setitem__(key, val_list) if key == 'Service': response.__setitem__(key, val_list) if key == 'ExportedService': response.__setitem__(key, val_list) if key == 'Taskaffinity': response.__setitem__(key, val_list) if key == 'ImplicitIntent': tmp_imp_intents = [] for key in val_list.keys(): tmp_imp_intents.extend(val_list[key]) key = 'ImplicitIntent' response.__setitem__(key, tmp_imp_intents) if key == 'Provider': tmp_providers = [] provider_obj_list = [] for key_parent, value_parent in val_list.items(): for key, value in value_parent.items(): if key == 'name': temp = key + ' : ' + value provider_obj_list.insert(0, temp) else: temp = key + ' : ' + value provider_obj_list.append(temp) provider_obj_list.append("") tmp_providers.extend(provider_obj_list) provider_obj_list = [] key = 'Provider' response.__setitem__(key, tmp_providers) return response