egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Read RSS feed or xml file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Gabzor
Voice


Joined: 10 Feb 2009
Posts: 3

PostPosted: Thu Nov 12, 2009 10:28 am    Post subject: Read RSS feed or xml file Reply with quote

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.
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Thu Nov 12, 2009 11:23 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gabzor
Voice


Joined: 10 Feb 2009
Posts: 3

PostPosted: Thu Nov 12, 2009 3:05 pm    Post subject: Reply with quote

-_-

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 & +...
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Fri Nov 13, 2009 8:36 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gabzor
Voice


Joined: 10 Feb 2009
Posts: 3

PostPosted: Fri Nov 13, 2009 10:22 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Fri Nov 13, 2009 12:09 pm    Post subject: Reply with quote

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:

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 :-

Quote:

[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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber