This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Read RSS feed or xml file

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
G
Gabzor
Voice
Posts: 3
Joined: Tue Feb 10, 2009 2:07 pm

Read RSS feed or xml file

Post by Gabzor »

Hello everybody.

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.

Can anyone help me?
Thank you.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

The key to grabbing data from http://localhost or http://127.0.0.1 is having a webserver running to serve up the http page when requested.

Did you have a webserver running on your computer when you tried?
I must have had nothing to do
G
Gabzor
Voice
Posts: 3
Joined: Tue Feb 10, 2009 2:07 pm

Post by Gabzor »

-_-

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 & +...
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Not sure you will get any takers on this one.

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.
I must have had nothing to do
G
Gabzor
Voice
Posts: 3
Joined: Tue Feb 10, 2009 2:07 pm

Post by Gabzor »

Thank you for your answer.

My .xml is very simple:

<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>Some title</title>
<link>http://blabla</link>
<description>The desctription</description>
<item>
<title>avadar moonie moonchine manufactured an item (OreAmp OA-101 (L)) worth 74 PED!</title>
<pubDate>Fri, 13 Nov 2009 14:17:23 +0000</pubDate>
</item>
<item>
<title>Piotr JIIIS Wojtowicz manufactured an item (Simple II Plastic Springs) worth 97 PED!</title>
<pubDate>Fri, 13 Nov 2009 14:17:16 +0000</pubDate>
</item>
...

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
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

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.

Code: Select all

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.
I must have had nothing to do
Post Reply