{'Status': {'Call': [{'id': 53, 'Status': 'Connected'}]}}
Below is part of my solution for dealing with nested endpoint response:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#accept input data and keys "Status" and "Call" | |
async def nested_get(input_dict, nested_key): | |
internal_dict_value = input_dict | |
for k in nested_key: | |
internal_dict_value = internal_dict_value.get(k, None) | |
if internal_dict_value is None: | |
return None | |
#test to ensure Status is part of the new list | |
test = any("Status" in d for d in internal_dict_value) | |
#if true return the final list value | |
if test == True : | |
final_list = [i["Status"] for i in internal_dict_value] | |
return final_list | |
else : | |
return None |
Feel free to suggest improvements to the code in the comments below. Let us call my solution so far crude but effective. Obviously this is not all of it but I will present the rest when I am done.
Finally today I have started preparing my Pi to run my new Python code. This is a very useful tutorial on get your Pi running the right version of Python 3.7.
VoIPNorm
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.