Refeed: How we got it to work

| | Comments (0) | TrackBacks (0)

First off since Movable Type 4.0 has been released I have been trying to get this plugin, refeed, to work. Finally after much gnashing of teeth and many swear words I decided I needed to find out if my perl install was even good or not. I couldn't find a ready script to test the perl modules that this plugin were using so I had to learn a little perl. I came up with the script below using the docs at cpan as a guide. So now I have this script that reads in an rss feed and then spits out the title of the feed followed by the time the article was published. This is where I discovered or at least confirmed what my problem with refeed was. XML::Feed wasn't properly reading in the time. <pubDate>2007-10-12 10:20:49-0400</pubDate> So now we know it isn't reading the time in right so what I did was enlisted the help of Corydon and he told me to change my $issued = $entry->issued; to my $issued = $entry->issued || DateTime->now(); the addition the line tells the script if the first field is undefined use this instead which is the current time. This has a few problems like all the posts from a feed would be read in the first time as all being posted at the same time after the initial pull it becomes less of a problem.

#!/usr/bin/perl

use Feed::Find;
use URI::Fetch;
use XML::Feed;

$url="http://www.memestreams.net/users/wilpig/?type=rss";

my @feeds = Feed::Find->find($url);
for my $uri (@feeds) {
print "$uri \n";
    my $res = URI::Fetch->fetch($feeds[0])
        or $warn->("Can't fetch feed $feeds[0], skipping"), next;

    my $feed = XML::Feed->parse(\$res->content)
        or $warn->("Can't parse feed $feeds[0], skipping"), next;

     for my $entry ($feed->entries) {
        my $id = $entry->id;
# Uses the current time if no time is found.
#        my $issued = $entry->issued || DateTime->now();
        my $issued = $entry->issued;
        $issued->set_time_zone('UTC');
        print "$id \n $issued \n";
     }
}

So after knowing what the problem was I asked again in #se2600 for some further help. Critch offered and helped me find a work around to this perl module not reading in the time correctly. So he had me edit /usr/lib/perl5/site_perl/5.8.8/XML/Feed/RSS.pm and we changed starting at line 224. This was the original section.

                my $parser = DateTime::Format::Mail->new;
                $parser->loose;
                $date = $parser->parse_datetime($ts);

and here is what we changed it to so that we knew exactly what format the time would be in once it was set to be parsed.

                my @time = localtime(HTTP::Date::str2time($ts));
                my $stringtime = Date::Format::strftime("%a, %d %b %Y %H:%M:%S %z",@time);
                my $parser = DateTime::Format::Mail->new;
                $parser->loose;
                $date = $parser->parse_datetime($stringtime);

This works as intended. However it does throw up a warning each time it is run talking about a difference in format but it doesn't seem to bother anything. Almost forgot at the top of the file we had to add in:

use HTTP::Date;
use Date::Format;

For the other modules we were using in parsing the time format.

There you have it. My test script to ensure that the perl modules are installed correctly and functioning and the changes we made to RSS.pm as well. Hope this helps someone.

Categories

0 TrackBacks

Listed below are links to blogs that reference this entry: Refeed: How we got it to work.

TrackBack URL for this entry: http://blog.wilpig.org/mt/mt-tb.cgi/164

Leave a comment

Semi-Live Cam

July 2008
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

About this Entry

This page contains a single entry by Wilpig published on October 16, 2007 8:37 AM.

Aftermath kills Illidan Stormrage was the previous entry in this blog.

Line of the day is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.2rc3-en
Print Posts