Reputation: 45
I have the following List of Item with for each of them an ID
List_Item = [['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:471b2fd7-d1f6-4fdd-a701-8d2426e2c67b'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fe43ed8e-1254-4bf3-a6d1-be4568861ce7'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:4ac881c8-942d-4bf2-8728-61ee8db55e74'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:24fa0bf7-af38-46aa-99c7-5d74a66e4132'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fd9f6f71-9e39-4777-8d99-80f3b0d9e314'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:7fee75ec-5ed7-4542-b62f-adb6879d7d35'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:51e5e086-91bd-411f-9987-46cb7376fd76'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:8a664472-45fb-45ce-9965-2087638635f6'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:e4d01008-4d15-4d64-825a-d17594a00d82'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:b76272c1-a295-4b0d-b67c-a6345ac066c3'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:7a767269-d0d9-4ce6-a655-355173778141'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:5f93f6d9-c0ce-4006-84bf-217cdab64fce'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:8d062331-77b9-4c5e-87d6-2e02adaf672c'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:fb63787e-f5a5-4d4b-b637-99d8354fc482'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:dc51d14f-cfcd-4688-a8f0-fea6129d77d1'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:f65ece95-6cb8-4ef9-99b3-28067af26b10'],
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:74588a7a-549f-4e07-a018-557fd8e9749c']
]
I would like to use this list of id in my script below as a parameter. The reason I want to do this is because in order to have access to information related to DataProcessingITem, I need to give the id of DataProcessing in order for the code to understand which information it needs to search for and brings back the information.
The purpose here is to use the id as a parameter in order to get this researched information. The tricky thing is that I need to do it for several id that have been stored in a list.
Someone has an idea how to achieve that?
for categoryItem in structureDictItem:
for endpointItem in structureDictItem[categoryItem]:
endpointFilenameItem = endpointItem
if categoryItem in ["types"]:
endpointFilenameItem = endpointItem.replace("/", "_")
url = DataGalaxy_url + endpointItem
params = {"versionId":Workspace_id,
"includeAccessData":"true",
"includeAttributes":"true",
"includeLinks":"true",
"limit":5000
}
jsonResponse = requests.get(url, params=params, headers={"Authorization":accessToken}).json()
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
try:
jsonResponsePages = jsonResponse['pages']
if int(jsonResponsePages) != 1:
for i in range(2, jsonResponsePages+1, 1):
for x in range(0,30):
params["page"] = str(i)
params["dataProcessingId"] = List_Item[x]
jsonResponse = requests.get(url=url, params = params, headers={"Authorization":accessToken}).json()['results']
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
except:
print(endpointItem)
next
I have tried something witht the following script but it told me that dataProcessingId must be a string
for categoryItem in structureDictItem:
for endpointItem in structureDictItem[categoryItem]:
endpointFilenameItem = endpointItem
if categoryItem in ["types"]:
endpointFilenameItem = endpointItem.replace("/", "_")
url = DataGalaxy_url + endpointItem
params = {"versionId":Workspace_id,
"includeAccessData":"true",
"includeAttributes":"true",
"includeLinks":"true",
"limit":5000
}
jsonResponse = requests.get(url, params=params, headers={"Authorization":accessToken}).json()
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
try:
jsonResponsePages = jsonResponse['pages']
if int(jsonResponsePages) != 1:
for i in range(2, jsonResponsePages+1, 1):
for x in range(0,30):
params["page"] = str(i)
params["dataProcessingId"] = List_Item[x]
jsonResponse = requests.get(url=url, params = params, headers={"Authorization":accessToken}).json()['results']
writeContentToFile('a', customername, workspacename, categoryItem, endpointFilenameItem, jsonResponse)
except:
print(endpointItem)
next
Upvotes: 0
Views: 33
Reputation: 6305
List_Item
is a list of lists, so when you do List_Item[int]
, it is returning another list
List_Item[0]
['5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:471b2fd7-d1f6-4fdd-a701-8d2426e2c67b']
You need to get the string inside the list:
List_Item[0][0]
'5f5e5b5a-1e2d-4c6a-bdf0-ec2bc233ab0c:471b2fd7-d1f6-4fdd-a701-8d2426e2c67b'
In addition, instead of using a range function to loop over the list, you can just loop over the list like:
for item in List_Item:
params["page"] = str(i)
params["dataProcessingId"] = item[0]
Upvotes: 1