Post by Core on May 10, 2009 17:30:08 GMT -5
Being new at programming Run Basic, and programming in general, I figured I would be nice to have a RSS feed reader. I read an article about how to create a feed reader in PHP, a language I know nothing about, and figured this will be good practice.
Run Basic has all the tools needed to create a reader, XML parser, Arrays, and the HTTPGET$ feature. I gave it a shot and I’m pretty happy with the preliminary results.
Learning how the XML parser worked was nothing short of ......... interesting.
I will defiantly spend more time perfecting the RSS reader engine as my knowledge of RB grows. Here is a sample of what I have so far, not perfect but functional.
Respectfully,
Core
Here is the direct link on my server.
hvacore.net/seaside/go/runbasicpersonal?app=RbSSv1
Here is the preliminary code:
Run Basic has all the tools needed to create a reader, XML parser, Arrays, and the HTTPGET$ feature. I gave it a shot and I’m pretty happy with the preliminary results.
Learning how the XML parser worked was nothing short of ......... interesting.
I will defiantly spend more time perfecting the RSS reader engine as my knowledge of RB grows. Here is a sample of what I have so far, not perfect but functional.
Respectfully,
Core
Here is the direct link on my server.
hvacore.net/seaside/go/runbasicpersonal?app=RbSSv1
Here is the preliminary code:
global z, varElements, #PE, #CE
titlebar "RbSS reader"
cssid #St1, "{
display: none;
background-color: transparent;
}"
cssid #Container, "{
position: relative;
top: 30px;
left: 30px;
width: 625px;;
height: 332px;
background: white;
color: black;
font-family: veranda,sans-serif;
margin-bottom: 5px;
padding: 3px 0;
overflow: hidden;
}"
cssid #Header, "{
position: absolute;
top: 0;
left: 0;
-moz-border-radius-topleft: 14px;
-webkit-border-top-left-radius: 14px;
-moz-border-radius-topright: 14px;
-webkit-border-top-right-radius: 14px;
border: 1px solid black;
width: 623px;
height: 65px;
color: white;
background-image: url('http://i445.photobucket.com/albums/qq179/ct315185/background-1.jpg');
z-index: 1;
}"
cssid #logo, "{
position: absolute;
top: 2px;
left: 6px;
width: 63px;
height: 63px;
z-index: 3;
}"
cssid #RbSStitle, "{
position: absolute;
top: 21px;
left: 160px;
font-size: 1.5em;
font-weight: bold;
}"
cssid #RbSStitleDate, "{
position: absolute;
top: 27px;
right: 10px;
font-size: 1.2em;
font-weight: bold;
}"
cssid #RbSStileDescriptiont, "{
position: absolute;
top: 70px;
left: 0;
border: 1px solid black;
width: 615px;
height: 40px;
padding: 4px;
background-image: url('http://i445.photobucket.com/albums/qq179/ct315185/GreenGradient.png');
color: white;
font-size: 1.1em;
font-weight: bold;
z-index: 2;
}"
cssid #Description, "{
position: absolute;
top: 123px;
left: 0;
width: 615px;
height: 200px;
overflow: hidden;
-moz-border-radius-bottomleft: 14px;
-webkit-border-bottom-left-radius: 14px;
-moz-border-radius-bottomright: 14px;
-webkit-border-bottom-right-radius: 14px;
border: 1px solid black;
padding: 4px;
}"
cssid #ElementTitle, "{
font-size: 1.2em;
font-weight: bold;
color: #660000;
}"
cssid #ElementDate, "{
font-size: 1em;
font-weight: bold;
color: green;
font-family: monospace;
}"
cssid #Selection, "{
position: absolute;
top: 460px;
left: 40px;
}"
textarea #Story1, "", 0, 0
#Story1 setid("St1")
a$ = httpget$("http://feeds.foxnews.com/foxnews/entertainment")
dim RssItemTitle$(varElements)
dim RssItemUrl$(varElements)
dim RssItemDescription$(varElements)
dim RssItemPubDate$(varElements)
#Story1 text(prepArrays(a$,varElements))
Redim RssItemTitle$(varElements)
Redim RssItemUrl$(varElements)
Redim RssItemDescription$(varElements)
Redim RssItemPubDate$(varElements)
#Story1 text(RBss$(a$))
[restart]
html "</div>
<div id = 'Container'>
<div id = 'Header'>
<span id = 'logo'><img src = 'http://i445.photobucket.com/albums/qq179/ct315185/rssFeedIc.png' width = '63' height = '63'></span>
<span id = 'RbSStitle'>"
print RssItemTitle$(1)
html "</span>
<span id = 'RbSStitleDate'>"
print RssItemPubDate$(1)
html "</span>
</div>
<div id = 'RbSStileDescriptiont'>"
print RssItemDescription$(1)
html "</div>
<div id = 'Description'><marquee bgcolor='lightyellow' scrollamount='1' direction='up' loop='true' width='100%'>"
for t = 4 to z - 1
html"<span id = 'ElementTitle'>":print RssItemTitle$(t):html "</span>"
html "<a href = '":print RssItemUrl$(t):html "' target='_new'>":print RssItemUrl$(t):html "</a>"
html "<span id = 'ElementDescrip'>":print RssItemDescription$(t):html "</span>"
html "<span id = 'ElementDate'>":print RssItemPubDate$(t):html "</span>"
print "-------------------------------"
print:print
next t
html " </marquee></div></div>
<div id = 'Selection'>
<fieldset>
<legend>Feed selection</legend>"
dim feeds$(8)
feeds$(1) = "http://rss.cnn.com/rss/cnn_topstories.rss"
feeds$(2) = "http://feeds.foxnews.com/foxnews/latest"
feeds$(3) = "http://rss.cnn.com/rss/cnn_tech.rss"
feeds$(4) = "http://feeds.foxnews.com/foxnews/scitech"
feeds$(5) = "http://rss.cnn.com/rss/cnn_space.rss"
feeds$(6) = "http://feeds.foxnews.com/foxnews/entertainment"
feeds$(7) = "http://www.nasa.gov/rss/breaking_news.rss"
feeds$(8) = "http://feeds.wired.com/wired/index?format=xml"
listbox #FeedXml, feeds$(), 0
button #accept, " Read it ", [FeedUrl]
html " </fieldset>
</div>"
wait
[FeedUrl]
a$ = httpget$("";#FeedXml selection$();"")
#Story1 text(prepArrays(a$,varElements))
Redim RssItemTitle$(varElements)
Redim RssItemUrl$(varElements)
Redim RssItemDescription$(varElements)
Redim RssItemPubDate$(varElements)
#Story1 text(RBss$(a$))
cls
goto [restart]
wait
' |||||||||||| RB functions |||||||||||||||
function prepArrays(feed$,b)
on error goto [parsingFailed]
xmlparser #rss, feed$
if #rss elementcount() then
for i = 1 to #rss elementcount()
#PE = #rss #element(i)
if #PE elementcount() then
for a = 1 to #PE elementcount()
#CE = #PE #element(a)
next a
end if
next i
end if
varElements = #PE elementcount()
prepArrays = varElements
end function
function RBss$(xml$)
on error goto [parsingFailed]
xmlparser #rss, xml$
z = 1
for i = 1 to #rss elementcount()
#PE = #rss #element(i)
if #CE key$() = "item" then
select case #CE key$()
case "item"
if #PE valueforkey$("title") <> " " then
RssItemTitle$(z) = #PE valueforkey$("title")
RssItemUrl$(z) = #PE valueforkey$("link")
RssItemDescription$(z) = #PE valueforkey$("description")
RssItemPubDate$(z) = date$()
z = z + 1
end if
end select
end if
next i
for b = 1 to varElements ' |||| #PE elementcount()
#CE = #PE #element(b)
if #CE key$() = "item" then
select case #CE key$()
case "item"
if #CE valueforkey$("title") <> " " then
RssItemTitle$(z) = #CE valueforkey$("title")
RssItemUrl$(z) = #CE valueforkey$("link")
D = instr(#CE valueforkey$("description"),"<",1)
RssItemDescription$(z) = left$(#CE valueforkey$("description"), D - 1)
RssItemPubDate$(z) = #CE valueforkey$("pubDate")
z = z + 1
end if
end select
end if
next b
end function
[parsingFailed]
print Err$
XmlError = XmlError + 1
if XmlError = 2 then
print "This RSS feed is not valid"
end
end if
goto [restart]