2014-06-14, 17:05
Hi all,
I'm writing the code to fetching the data from the xml file on my server so I can stored the data in a sqlite3 database. Now I want to pull the data from the database under the columns called channel, title, start_date and stop_date.
Here is the code:
How do you pull the data from the database under the colums called channel, title, start_date and stop_date for each channel to print them?
Thanks in advance
I'm writing the code to fetching the data from the xml file on my server so I can stored the data in a sqlite3 database. Now I want to pull the data from the database under the columns called channel, title, start_date and stop_date.
Here is the code:
Code:
#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('allchannels.url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
if os.path.exists(profilePath):
profilePath = profilePath + 'source.db'
con = database.connect(profilePath)
cur = con.cursor()
cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
con.commit()
con.close
tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
profilePath = profilePath + 'source.db'
con = sqlite3.connect(profilePath)
cur = con.cursor()
channels = OrderedDict()
# Get the loaded data
for channel in tv_elem.findall('channel'):
channel_name = channel.find('display-name').text
for program in channel.findall('programme'):
title = program.find('title').text
start_time = program.get("start")
stop_time = program.get("stop")
cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
con.commit()
print 'Channels store into database are now successfully!'
cur.execute('SELECT channel, title, start_date, stop_date FROM programs')
cur.close
programList = list()
channelMap = dict()
How do you pull the data from the database under the colums called channel, title, start_date and stop_date for each channel to print them?
Thanks in advance