I am working on learning to code an application using the SLACK API and Python 3. It provides a JSON response object, only I am finding that my knowledge in list/dictionary comprehension is severely lacking. I am really having a hard time figuring out how to work the syntax to extract the particular information from the following JSON object:
"channels": [
{
"id": "C73HHT2TZ",
"name": "general",
"is_channel": true,
"created": 1465530333,
"creator": "V35HUT43C",
"is_archived": false,
"is_general": true,
"has_pins": false,
"is_member": true,
"last_read": "1467334012.000165",
"latest": {
"type": "message",
"user": "USLACKBOT",
"text": "Good bye. See you when you return...",
"ts": "1467334012.000165"
},
"unread_count": 0,
"unread_count_display": 0,
"members": [
"X95HUT43C",
"Ad5RQAAHZ",
"X45SY5VEH"
]
In the above JSON object, I am able to retrieve the entire raw 'Channel' dump using:
response = slack.rtm.start()
listening = response.body['channels']
for i in listening:
print(i)
I have tried this as well to no avail:
response = slack.rtm.start()
listening = response.body['channels'][0]
for i in listening:
print(i)
but this just gets me the following:
id
is_archived
is_general
purpose
name
is_channel
unread_count
members
has_pins
created
topic
creator
unread_count_display
latest
is_member
last_read code here
I am getting warmer, but unfortunately this is just a mess and I really can't seem to wrap my head around how to figure out how to get to the info in the following path:
'channels': > 'latest': > 'text': > and ultimately the value of 'text'
How would I go about doing this?