Post by David Drake on Dec 24, 2019 13:32:09 GMT -5
Below I've pasted some code I whipped up for a text-based RSS news reader for the BBC news feed. It pulls the latest news via HTTPGET, parses the file, and presents the headlines in a beautifully simple MAINWIN interface. Have fun with this demo! - David
[start]
itemCount=0
displayCount=0
dim lines$(1000)
dim item$(1000,5)
[getRSSdata]
print "getting rss file..."
newsData$=httpget$("http://feeds.bbci.co.uk/news/rss.xml")
print "success..."
open "news.dat" for output as #1
print #1, newsData$
close #1
newsData1$ = REPLSTR$(newsData$,chr$(10),chr$(13))
open "news2.dat" for output as #3
print #3, newsData1$
close #3
open "news2.dat" for input as #4
lineCount=0
while eof(#4)<>-1
lineCount = lineCount + 1
line input #4, lines$(lineCount)
wend
close #4
'parse the data
for a = 1 to lineCount
if instr(lines$(a),"<item>")>0 then
itemCount = itemCount+1
dummy1a$ = replstr$(lines$(a+1),"<title><![CDATA[","")
dummy1b$ = replstr$(dummy1a$,"]]></title>","")
item$(itemCount,1) = trim$(dummy1b$)
dummy2a$ = replstr$(lines$(a+2),"<description><![CDATA[","")
dummy2b$ = replstr$(dummy2a$,"]]></description>","")
item$(itemCount,2) = trim$(dummy2b$)
dummy3a$ = replstr$(lines$(a+3),"<link>","")
dummy3b$ = replstr$(dummy3a$,"</link>","")
item$(itemCount,3) = trim$(dummy3b$)
dummy4a$ = replstr$(lines$(a+5),"<pubDate>","")
dummy4b$ = replstr$(dummy4a$,"</pubDate>","")
item$(itemCount,4) = trim$(dummy4b$)
end if
next a
[updateNews]
cls
print "Total of ";itemCount;" BBC news stories"
for i = 1 to 5
displayCount = displayCount+1
if displayCount > itemCount then [noMoreNews]
print "[";displayCount;"] ";item$(displayCount,1)
next i
print
print "Press ENTER for next items, Q to quit, or type number for more info..."
input z$
if upper$(z$) = "Q" then print "Bye":end
cls
if z$ = "" then [updateNews]
if val(z$) >= displayCount-5 and val(z$)<=displayCount then
print "MORE for [";z$;"] ";item$(val(z$),1)
print
for j = 2 to 4
print "* ";item$(val(z$),j)
next j
end if
print
input "Want to go to story in web browser (Y/N)?"; q$
if upper$(q$)="Y" then
run "explorer.exe ";item$(val(z$),3)
print "Opening browser..."
print
end if
displayCount = displayCount-5
goto [updateNews]
[noMoreNews]
print "End of news feed"
print "Press ENTER to refresh, Q to quit, or type number for more info..."
input z$
if upper$(z$) = "Q" then print "Bye":end
if z$ = "" then [start]