I know there are a few rss feed reader already/xml parsing file, but none worked for what I want to do.
I have an eggdrop, and I'm trying to make it parse infos from a rss feed that is on the same computer (can access it directly from http://localhost/... or can be accessed directly using system path).
I would like it to read the feed every 5 seconds and send new infos to a channel.
OR
Make it read directly the .xml and send new infos to a channel.
I have a webserver, the problem is making a script that reads the rss feed every 5 seconds... I've tried a few and they all only work for 1 minute & +...
RSS feed scripts poll a suitable site at fixed (usually configurable) intervals using a Tcl TIME bind. The smallest time interval that a TIME bind can deal with is 1 minute. An alternative approach using utimers would have to be used to accomplish polling at secondly intervals with the additional potential problem of not receiving data from one poll before the next poll is due (if a small number of seconds frequency is used). Although I appreciate that is unlikely to be the case when polling http://localhost.
If I was coding something suitable, I think I would consider looking at the format of the page/file and use file handling routines to grab the information. It really depends on the complexity of (and variations in) the file, plus the information you want to grab.
File handling routines to grab the information would be easy I think. But I would also need it to not copy the same line 2 times... Would need to store last title & pubDate read in another file, and check from there? Don't know how to do the whole thing tho :s
Hopefully, to give you some ideas of file reading the following script provides a public command !xml that extracts data from a file. I used the xml data you pasted above to create a file whatever.xml in the bot's root directory.
bind PUB - !xml pXMLRead
proc pXMLRead {nick uhost hand chan text} {
set fp [open whatever.xml r]
set data [split [read -nonewline $fp] \n]
close $fp
foreach line $data {
if {[regexp -- {<title>([^<]+)</title>} $line -> title]} {continue}
if {[regexp -- {<pubDate>([^<]+)</pubDate>} $line -> pubDate]} {continue}
}
if {[info exists title]} {putserv "PRIVMSG $chan :last title = $title"}
if {[info exists pubDate]} {putserv "PRIVMSG $chan :last pubDate = $pubDate"}
return 0
}
The IRC output is shown below :-
[16:01] <@arfer> !xml
[16:01] <@osmosis> last title = Piotr JIIIS Wojtowicz manufactured an item (Simple II Plastic Springs) worth 97 PED!
[16:01] <@osmosis> last pubDate = Fri, 13 Nov 2009 14:17:16 +0000
It would simply be a matter of invoking the code, or similar, repetitively using utimers rather than using a public command for a one-off output.