ok use the following code and see if you can understand.....by right i should use and xml parser but i have not used it so i am using regular expressions instead...
your going to have to to the rest yourself!
:lol:
import urllib,urllib2 , re
import xml.dom.minidom
import xbmc, xbmcgui
from string import split, replace, find
try: emulating = xbmcgui.emulating
except: emulating = false
action_move_left = 1
action_move_right = 2
action_move_up = 3
action_move_down = 4
action_page_up = 5
action_page_down = 6
action_select_item = 7
action_highlight_item = 8
action_parent_dir = 9
action_previous_menu = 10
action_show_info = 11
action_pause = 12
action_stop = 13
action_next_item = 14
action_prev_item = 15
txheaders = {
'user-agent': 'mozilla 1.0',
'accept-language': 'en-us',
}
txdata = none
class cheadline:
def (self, title, description, link):
self.title = title
self.description = description
self.link = link
class bbc(xbmcgui.window):
def (self):
if emulating: xbmcgui.window.(self)
self.scalex = ( float(self.getwidth()) / float(720) )
self.scaley = ( float(self.getheight()) / float(480) )
self.background = xbmcgui.controlimage(0,0, int(720*self.scalex),int(480*self.scaley), 'q:\\scripts\\background.png')
self.headlinelist = xbmcgui.controllist(int(50*self.scalex), int(50*self.scaley), int(450*self.scalex), int(350*self.scaley))
self.addcontrol(self.headlinelist)
self.headlinelist.setvisible(1)
self.setfocus(self.headlinelist)
self.headlines = self.getheadlines('
http://news.bbc.co.uk/rss/newsonline_uk_...ss091.xml')
for c in self.headlines:
self.headlinelist.additem(c.title)
def oncontrol(self, control):
if control == self.headlinelist:
desc = self.headlines[self.headlinelist.getselectedposition()].description
link = self.headlines[self.headlinelist.getselectedposition()].link
print (desc)
print (link)
def getheadlines(self,url):
rss_data = self.gethtmldata(url)
#<item>
#<title>carlisle reels from flood chaos</title>
#<description>flooding in carlisle leaves schools and roads closed and the city's court and hospital running skeleton services.</description>
#<link>
http://news.bbc.co.uk/go/click/rss/0.91/...stm</link>
#</item>
out = []
headlinesre = re.compile('<item>.+?<title>(.+?)</title>.+?<description>(.+?)</description>.+?<link>(.+?)</link>.+?</item>',re.multiline + re.dotall)
headlines = headlinesre.findall(rss_data)
for headline in headlines:
print(headline[0])
print(headline[1])
print(headline[2])
out.append(cheadline(headline[0],headline[1],headline[2]))
return out
def gethtmldata(self,url):
req = urllib2.request(url, txdata, txheaders)
try:
response = urllib2.urlopen(req)
except urllib2.httperror, error:
print ("error retrieving data : " + error)
if not emulating:
error_dialog = xbmcgui.dialog()
error_dialog.ok("net error", error)
return error
html = response.read()
response.close()
return html
def correctchars(self,txt):
data = txt
data = replace(data,'&','\'')
data = replace(data,''','\'')
data = replace(data,'"','"')
data = replace(data,'&;','&')
data = replace(data,'\n','')
return data
w = bbc()
w.domodal()
del w