I have a dictionary that has a table ID as key and table name as value and another list that has a list of dicts of that corresponds to table refresh policies. I am trying to dynamically pass dictionary values and list elements to a JSON blob and then pass that to an API post request but looks like I'm sending duplicate requests to the post request.
P.S: This is just sample data that looks like original data.
d = {101: bh,
102: cy,
103: ui,
104: act}
l = [{'refresh_method': 'FULL'},
{'refresh_method': 'FULL'},
{'refresh_method': 'INCREMENTAL', 'refresh_field': 'updated_at'},
{'refresh_method': 'INCREMENTAL', 'refresh_field': 'updated_at'}]
for key, value in d.items():
for a in l:
payload = {
"entityType": "dataset",
"id": key,
"path": value,
"type": "PHYSICAL_DATASET",
"accelerationRefreshPolicy": {
"method": a['refresh_method'],
"refreshField": a['refresh_field'],
"neverRefresh": True,
"neverExpire": True,
},
}
resp = requests.requests('POST', url, json=payload)
When I print the payload I don't see the values from the second loop. Is it because of two loops? Is there a better way to do it?
{'entityType': 'dataset', 'id': 101, 'path': ['db', 'public', 'bh'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'INCREMENTAL', 'refreshField': 'updated_at', 'neverRefresh': True, 'neverExpire': True}}
{'entityType': 'dataset', 'id': 102, 'path': ['db', 'public', 'cy'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'INCREMENTAL', 'refreshField': 'updated_at', 'neverRefresh': True, 'neverExpire': True}}
{'entityType': 'dataset', 'id': 103, 'path': ['db', 'public', 'ui'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'INCREMENTAL', 'refreshField': 'updated_at', 'neverRefresh': True, 'neverExpire': True}}
{'entityType': 'dataset', 'id': 104, 'path': ['db', 'public', 'act'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'INCREMENTAL', 'refreshField': 'updated_at', 'neverRefresh': True, 'neverExpire': True}}
Expected result:
{'entityType': 'dataset', 'id': 101, 'path': ['db', 'public', 'bh'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'FULL', 'refreshField':'', 'neverRefresh': True, 'neverExpire': True}}
{'entityType': 'dataset', 'id': 102, 'path': ['db', 'public', 'cy'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'FULL', 'refreshField': '', 'neverRefresh': True, 'neverExpire': True}}
{'entityType': 'dataset', 'id': 103, 'path': ['db', 'public', 'ui'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'INCREMENTAL', 'refreshField': 'updated_at', 'neverRefresh': True, 'neverExpire': True}}
{'entityType': 'dataset', 'id': 104, 'path': ['db', 'public', 'act'], 'type': 'PHYSICAL_DATASET', 'accelerationRefreshPolicy': {'method': 'INCREMENTAL', 'refreshField': 'updated_at', 'neverRefresh': True, 'neverExpire': True}}
Really appreciate it if I can get some help here.