tim_manger
07/20/2023, 1:56 AM{
"dob": "20230718",
"storeId": "psi136678",
"checks": [
{
"id": "9437185",
"isClosed": true,
"isEmpty": false,
"isTraining": false,
"link": "<https://www.api.com/v1/psi136678/20230718/sales/check/9437185>",
"marker": 638252250666959000,
"netAmount": 18.26,
"printableId": "90001",
"total": 21
},
{
"id": "8388609",
"isClosed": true,
"isEmpty": false,
"isTraining": false,
"link": "//www.api.com/v1/psi136678/20230718/sales/check/8388609",
"marker": 638252253271407100,
"netAmount": 9.13,
"printableId": "80001",
"total": 10.5
}
]
}
API to call https<//www.api.com/v1/{storeId}/{dob}/sales/check/{Checks.id}>
I am having trouble trying to extract the data in the correct format to pass to the return{} in my streams.py.
Below is my def_child_Context, but it keeps failing to run the API call
def get_child_context(self, record: dict, context: dict) -> dict:
"""Return a context dictionary for child streams."""
checks = record.get('checks', []) # Retrieve the checks array from the record, providing an empty list as a default value
check_ids = [int(check.get('id')) for check in checks]
# Extract the desired "id" values
i = 0
for check in record["checks"]:
desired_ids = [{"storeId": record["storeId"],
"dob": record["dob"],
"id": record["checks"][i]["id"]} ]
i = i + 1
desired_ids.append(desired_ids)
output = json.dumps(desired_ids)
res_dict = {}
for i in range(0, len(desired_ids), 2):
res_dict[desired_ids[i]] = desired_ids[i + 1]
return {
storeId": res_dict["storeId"],
dob": res_dict["dob"],
id": res_dict["id"],
}
I have altered my code and it works without failing. However, it only returns one check not all checks
def get_child_context(self, record: dict, context: dict) -> dict:
"""Return a context dictionary for child streams."""
desired_data_list = []
for check in record["checks"]:
desired_data = {
"dob": record["dob"],
"storeId": record["storeId"],
"id": check["id"]
}
desired_data_list.append(desired_data)
return {
"storeId": desired_data_list[0]["storeId"],
"dob": desired_data_list[0]["dob"],
"id": desired_data_list[0]["id"],
}
I tried moving the return into the loop, but it will still only return on check detail. There should be hundreds
is anyone able to suggest a solution or see where the errors are in my code?
Thank you for any help
Timedgar_ramirez_mondragon
07/20/2023, 7:13 PMedgar_ramirez_mondragon
07/20/2023, 7:18 PMtim_manger
07/20/2023, 9:10 PMedgar_ramirez_mondragon
07/20/2023, 9:31 PMtim_manger
07/20/2023, 11:28 PM