Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I don't know if I'm going off on the wrong tanget here but I've been trying to come up with a short script that automates the fetching of two nodes in an RSS feed. What I'm aiming to do is to send any new items to Twitter (the code which I've already got working). I'm working on the way of making sure that I'm only fetching two (or any number) items and that they are new. I had thought of putting them nodes in a hash (as databasing them would be overkill) and comparing them but is there a better way of doing this and also how would I limit the number of items found as my previous attempts have failed dismally. I'm also limited by the packages on the server to these modules rather than being able to use XML::RSS and the $desc gives me some detail which my LWP::UA attempt stripped out (it has a hyperlink in it).
use strict; use warnings; use LWP::Simple; use XML::LibXML; my $tickets = qw(localhost/rss); my $feed = get($tickets); my $parser = XML::LibXML->new; my $doc = $parser->parse_string($feed); my $date = $doc->findvalue('rss/channel/item/pubDate'); my $desc = $doc->findvalue('rss/channel/item/description'); my %hash = ($date, $desc);
I'd be grateful for any pointers in the two issues.

Replies are listed 'Best First'.
Re: Automating RSS fetching and comparing
by Your Mother (Archbishop) on Aug 01, 2008 at 15:19 UTC

    I'm working on a fairly sophisticated version of this (minus the Twitter) idea right now. XML::Feed is your friend. While I find some of the interface annoying (you can't set your own user agent for example) it's really a very slick package. You'll probably want to read up on DateTime as well so you can deal with feed dates which come back as DateTime objects.

Re: Automating RSS fetching and comparing
by Erez (Priest) on Aug 01, 2008 at 16:54 UTC
Re: Automating RSS fetching and comparing
by merlyn (Sage) on Aug 02, 2008 at 10:39 UTC
      Thanks everybody for the advice. Lots of Perl goodness to think and try.