<html><head></head><body><span class="viv-signature"></span>On Thursday 23
February 2023 02:14:02 PM (-06:00), George Bingham
wrote:<br><br><blockquote style="margin: 0 0 0.80ex; border-left: #0000FF
2px solid; padding-left: 1ex"><div dir="ltr">Hello List
folk,<div><br></div><div>This question may not be appropriate for this
forum, so please redirect me if there's a better way to get this
answered....</div><div><br></div><div>I'm playing with some python code to
get guide data similar to what mythweb does with the guide. Although I'm
only interested in a subset of the full guide
data.</div><div><br></div><div>Anyway, I am using the Channel Service
'GetChannelInfoList' and am trying to loop my way through it to see the
chanId, chanNum, CallSign.</div><div><br></div><div>The data structures
that most of these service api requests result in is confusing to me. How
do I know what's a dictionary and what's a list? When it's a dictionary,
how do I know what the keys are?</div><div>Here's an example of a loop
where I'm trying to traverse the results... This isn't part of any actual
project yet, I'm just trying to understand how to examine and use the
results of these queries...</div><div><br></div><div><font size="1"
face="monospace">
resp_dict=backend.send(endpoint="Channel/GetChannelInfoList?SourceID=0&StartIndex=1&Count=33&OnlyVisible=true&Details=false")<br>
print ("Response from channel Info query: ", resp_dict)<br>
channelInfos=resp_dict['ChannelInfoList']<br>
c=0<br> for chan in channelInfos:<br>
print(channelInfos[c]['ChanID'], channelInfos[c]['ChanNum'],
channelInfos[c]['CallSign'])<br>
c+=1</font></div><div><font size="1"><br></font></div><div>The print
command in the for loop is generating an error, "KeyError: 0"</div><div>But
I used to have the 'chan' from the for loop there and it was giving me an
error about indices must be integers, not strings, so I'm not sure if it's
a list or a dict or what the heck it is...</div><div><br></div><div>How is
one supposed to determine the structures of data that are returned by the
service api calls???</div><div><br></div><div>Thanks for any
insight!!<br><div><div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">-- George</div></div></div></div>
</blockquote><span class="viv-signature-below"><div><span
class="viv-signature-below"><br></span></div><div><span
class="viv-signature-below">Take a peek at this:</span></div><div><span
class="viv-signature-below"><br></span></div><div><span
class="viv-signature-below"><div>#!/usr/bin/python3
</div><div>
</div><div>import json
</div><div>from MythTV.services_api import send as api
</div><div>
</div><div>
</div><div>def main():
</div><div>
</div><div> backend =
api.Send(host='localhost')
</div><div>
</div><div>
resp_dict=backend.send(endpoint="Channel/GetChannelInfoList",
</div><div>
rest="SourceID=0&StartIndex=1&Count=33&OnlyVisible=true&Details=false") </div><div>
</div><div> #print(json.dumps(resp_dict,
sort_keys=True, indent=4,
</div><div> #
separators=(',', ': ')))
</div><div>
</div><div> channelInfos =
resp_dict['ChannelInfoList']['ChannelInfos']
</div><div>
</div><div>
print(json.dumps(channelInfos, sort_keys=True, indent=4,
</div><div>
separators=(',', ':
')))
</div><div>
</div><div> for chan
in range(0, int(resp_dict['ChannelInfoList']['Count'])):
</div><div>
print(channelInfos[chan]['ChanId'],
</div><div>
channelInfos[chan]['ChanNum'],
</div><div>
channelInfos[chan]['CallSign'])
</div><div>
</div><div>
</div><div>if
__name__ == '__main__':
</div><div>
main()</div><div><br></div><div><br></div><div>Note that it's ChanId, not
ChanID. The json.dumps() method is helpful to see
what's</div><div>returned. Or, you can just send the message to a
browser.</div><div><br></div><div>Things in [] are lists. Things in {} are
dictionaries. I hardcoded the host, your args.host is</div><div>probably
fine.</div><div><br></div></span></div>-- <br>Bill</span></body></html>