Hi all
I need your help, I'm working on my python script to fetch the list of channels from the sqlite3 database.
I'm fetching 7 channels to set each channel in each label control 4010, 4011, 4012, 4013, 4014, 4015 and 4016. When I fetch the list of channels to put them in each label, I will get an error: IndexError: list index out of range
When I use this code:
CHANNELS_PER_PAGE = 7
#Pull the data from the database
channelList = list()
database_path = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', 'source.db'))
if os.path.exists(database_path):
#get the channels list
cur.execute('SELECT channel FROM programs WHERE channel GROUP BY channel')
for row in cur:
channels = row[0].encode('ascii')
channelList.append(channels)
# set the channels text
for index in range(0, CHANNELS_PER_PAGE):
self.getControl(4110 + index).setLabel(channelList[index])
Here is the list of channels when I print it:
17:02:10 T:6400 NOTICE: 101 ABC FAMILY
17:02:10 T:6400 NOTICE: 102 CBS
17:02:10 T:6400 NOTICE: 103 CNN USA
17:02:10 T:6400 NOTICE: 105 ESPN USA
17:02:10 T:6400 NOTICE: 106 Fox News
17:02:10 T:6400 NOTICE: 107 Animal Planet
17:02:10 T:6400 NOTICE: 108 USA Network
17:02:10 T:6400 NOTICE: 110 SPIKE
17:02:10 T:6400 NOTICE: 111 BRAVO USA
17:02:10 T:6400 NOTICE: 112 BRAVO1
17:02:10 T:6400 NOTICE: 113 BRAVO2
17:02:10 T:6400 NOTICE: 114 BRAVO3
17:02:10 T:6400 NOTICE: 115 BRAVO4
17:02:10 T:6400 NOTICE: 116 BRAVO5
17:02:10 T:6400 NOTICE: 117 BRAVO6
17:02:10 T:6400 NOTICE: 118 BRAVO7
I want to get 7 strings to set each string in the label control like this:
4010 ABC FAMILY
4011 CNN USA
4012 ESPN USA
4013 Fox News
4014 Animal Planet
4015 USA Network
4016 SPIKE
Here is the result:
4010 ABC FAMILY