Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:32 12 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Pi-cromite RSS reader

Author Message
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 07:16am 04 Oct 2018
Copy link to clipboard 
Print this post

Here is some code for parsing RSS feeds. I was interested in recovering weather feeds but the code can be used on other feeds such as News items etc.

I am using Curl on the Pi Zero to access the URL which seems to work nicely, is non blocking and also leaves the web socket free on the pi-cromite , useful as I can use UDP at the same time without open and closing ports.

I have set up a "script" to access a feed at Weather.com.au but other providers like Weatherzone have rss feeds.
Their Web page is here

Here is the code to date followed by the output from the above mentioned feed.

'Michael Ogden Codenquilts.com.au
'Oct 2018
'Weather.com.au RSS feed recovery

'
'version 0.5 ,

dim integer a(1000)
dim l%
dim xp
system "curl http://rss.weather.com.au/vic/moe",a()
for i=1 to llen(a())
print lgetstr$(a(),i,1);
next i
l%=0
xp=1

'"script" for Weather.com.au feed
print xml$(a(),"title",xp)
print xml$(a(),"description",xp)
print xml$(a(),"pubDate",xp)
print xml$(a(),"ttl",xp)
print xml$(a(),"title",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<b>",xp)
print xml$(a(),"<p>",xp)
print xml$(a(),"<p>",xp)
print xml$(a(),"<p>",xp)
print:xp=1
print xml$(a(),"<w:current",xp)
print xml$(a(),"<w:current",xp)
print xml$(a(),"<w:current",xp)
print xml$(a(),"<w:forcast",xp)
print xml$(a(),"<w:forcast",xp)
print xml$(a(),"<w:forcast",xp)
end



function xml$(xaray%(),xstr$,xp)
local xstart,xend,xlen,xreturn
local xstr1$
xlen=len(xstr$)
' extract required string
if xstr$="<b>" then
xlen=len(xstr$)
xstart=linstr(xaray%(), xstr$ ,xp)
xend=linstr(xaray%(),"<br />",xstart+xlen)
xreturn=xend-(xstart+xlen)
xp=xend+7
elseif xstr$="<p>" then
xlen=len(xstr$)
xstart=linstr(xaray%(), xstr$ ,xp)
xend=linstr(xaray%(),"</p>",xstart+xlen)
xreturn=xend-(xstart+xlen)
xp=xend+4
elseif xstr$="<w:current" or xstr$="<w:forcast" then
xlen=len(xstr$)
xstart=linstr(xaray%(), xstr$ ,xp)
xend=linstr(xaray%(),"/>",xstart+xlen)
xreturn=xend-(xstart+xlen)
xp=xend+2
else
xlen=len(xstr$)+2
xstart=linstr(xaray%(),"<" + xstr$ +">",xp)
xend=linstr(xaray%(),"</" + xstr$ +">",xstart+xlen)
xreturn=xend-(xstart+xlen)
xp=xend+xlen+4
end if
if xstart>0 then
'print "Total";xreturn
if xreturn > 255 then
xx=xstart+xlen+256
'get just 255 bytes and exit
on error skip
xstr1$=lgetstr$(xaray%(),xstart+xlen,255)
'remove any html tags etc
xml$=tags$(xstr1$)
else
on error skip
xml$=lgetstr$(xaray%(),xstart+xlen,xreturn)
'remove any html tags etc
xml$=tags$(xml$)
end if
end if
exit_xml:
'print xstart;" ";xend;" ";xlen;" ";xreturn;" ";xp
end function

'replaceString$(string$, replaceWhat$, replaceWith$)
FUNCTION replace$(R$, a$, b$)
local integer i,j,c,d
d=1
replace$=R$
i = LEN(a$) : j = LEN(b$)
do while INSTR(d,replace$, a$) > 0
c = INSTR(d,replace$, a$)
replace$ = LEFT$(replace$, c-1) + b$ + MID$(replace$, c+i)
d = c+j
loop
END FUNCTION

function tags$(t$)
t$=replace$(t$,"<![CDATA[","") 'remove cdata open tag
t$=replace$(t$,"<b>","") 'remove <b> open tag
t$=replace$(t$,"</b>"," ") 'replace <b> close tag with space
t$=replace$(t$,"&","") 'remove & Char
t$=replace$(t$,";","") 'remove ; Char
t$=replace$(t$,"<br />",chr$(13)) 'replace <br /> tag with LF
t$=replace$(t$,"]]>","") 'remove cdata close tag
t$=replace$(t$,"<","") 'remove open tag
t$=replace$(t$,">","") 'remove close tag
tags$=t$
end function


Weather.com.au - Moe Weather
Current conditions and forecast for Moe, Victoria.
Thu, 04 Oct 2018 06:45:00 GMT
15
Moe Current Conditions
Temperature: 11.9degC
Dew Point: 9.6degC
Relative Humidity: 86%
Wind Speed: 14.8km/h
Wind Gusts: 24.1km/h
Wind Direction: E
Pressure: 1022.1hPa
Rain Since 9AM: 0.0mm

Friday:
img src="//m6e6i3k5.stackpathcdn.com/images/icons/12.gif" alt="Early Fog Followed by Sun" /
Early Fog Followed by Sun. Mild.
7 - 18


Saturday:
img src="//m6e6i3k5.stackpathcdn.com/images/icons/2.gif" alt="Mostly Sunny" /
Mostly Sunny. Mild.
6 - 22


Sunday:
img src="//m6e6i3k5.stackpathcdn.com/images/icons/4.gif" alt="Afternoon Clouds" /
Afternoon Clouds. Mild.
8 - 24


temperature="11.9" dewPoint="9.6" humidity="86" windSpeed="14.8" windGusts="24.1" windDirection="E" pressure="1022.1" rain="0.0"

temperature="11.9" dewPoint="9.6" humidity="86" windSpeed="14.8" windGusts="24.1" windDirection="E" pressure="1022.1" rain="0.0"





Edited by MikeO 2018-10-05
Codenquilts
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 08:57am 04 Oct 2018
Copy link to clipboard 
Print this post

Mike

Thanks for posting - another innovative use. I also like the XML parser, this could be a very useful generic routine.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025