<div dir="ltr">Thanks Hika & Bill,<div><br></div><div>Both your inputs are very helpful!</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">-- George</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 23, 2023 at 4:07 PM Bill Meek <<a href="mailto:keemllib@gmail.com">keemllib@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><span></span>On Thursday 23 
February 2023 02:14:02 PM (-06:00), George Bingham 
wrote:<br><br><blockquote style="margin:0px 0px 0.8ex;border-left:2px solid rgb(0,0,255);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">-- George</div></div></div></div>
</blockquote><span><div><span><br></span></div><div><span>Take a peek at this:</span></div><div><span><br></span></div><div><span><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></div>_______________________________________________<br>
mythtv-users mailing list<br>
<a href="mailto:mythtv-users@mythtv.org" target="_blank">mythtv-users@mythtv.org</a><br>
<a href="http://lists.mythtv.org/mailman/listinfo/mythtv-users" rel="noreferrer" target="_blank">http://lists.mythtv.org/mailman/listinfo/mythtv-users</a><br>
<a href="http://wiki.mythtv.org/Mailing_List_etiquette" rel="noreferrer" target="_blank">http://wiki.mythtv.org/Mailing_List_etiquette</a><br>
MythTV Forums: <a href="https://forum.mythtv.org" rel="noreferrer" target="_blank">https://forum.mythtv.org</a><br>
</blockquote></div>