Part 2: Webex Board + Rasp Pi + BlyncLight = Python Dicts and Lists

So following on from part 1, today was spent going through Python tutorials on dealing with dictionaries and lists and how to create actions with the feedback data from a Collaboration endpoint. While I ended up with a working solution I am sure it is nowhere near optimal. Searching for a nested value in a dictionary that is in a list which has another dictionary had it complications. I managed to narrow down call status get events to:

{'Status': {'Call': [{'id': 53, 'Status': 'Connected'}]}}

Below is part of my solution for dealing with nested endpoint response:

#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
view raw nested_get.py hosted with ❤ by GitHub

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.