/[Grep]/lib/Grep/Source/Feed.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/Grep/Source/Feed.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 169 - (hide annotations)
Wed Jul 4 09:58:06 2007 UTC (16 years, 10 months ago) by dpavlin
File size: 1566 byte(s)
update rest of code to new created_on and last_update
1 dpavlin 72 # Dobrica Pavlinusic, <dpavlin@rot13.org> 02/22/07 19:42:14 CET
2    
3     use strict;
4     use warnings;
5    
6     package Grep::Source::Feed;
7    
8 dpavlin 104 use base 'Jifty::Object';
9    
10 dpavlin 72 use Data::Dump qw/dump/;
11    
12     =head2 fetch
13    
14 dpavlin 110 Grep::Source::Feed->fetch( $source_obj );
15 dpavlin 72
16     =cut
17    
18     sub fetch {
19     my $self = shift;
20    
21 dpavlin 110 my $parent = shift || $self->log->confess('no parent?');
22 dpavlin 72 my ($feed,$uri) = ($parent->feed, $parent->uri);
23     die "no uri" unless ($uri);
24     die "feed is not a Grep::Model::Feed but ", ref $feed unless $feed->isa('Grep::Model::Feed');
25    
26     my $ua = LWP::UserAgent->new;
27     $ua->default_header( 'Cookie' => $feed->cookie );
28     my $r = $ua->get( $uri );
29     die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success );
30     my $content = $r->content;
31    
32 dpavlin 99 $parent->save('feed.xml', $content);
33 dpavlin 86
34 dpavlin 72 die "No content returned from $uri\n" unless length( $content ) > 1;
35    
36     my $xml_feed = XML::Feed->parse( \$content )
37     or die $feed->title, " returned ", XML::Feed->errstr, "\n";
38    
39 dpavlin 110 $self->log->debug("getting ", scalar $xml_feed->entries, " entries from ", $xml_feed->format, " feed ", $xml_feed->title);
40 dpavlin 72
41     for my $entry ($xml_feed->entries) {
42    
43     $parent->add_record(
44     in_feed => $feed,
45 dpavlin 99 title => $entry->title || $entry->link,
46 dpavlin 72 link => $entry->link,
47     content => $entry->content->body,
48     summary => $entry->summary->body,
49     category => $entry->category,
50     author => $entry->author,
51 dpavlin 169 created_on => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S") : undef,
52     last_update => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S") : undef,
53 dpavlin 72 );
54    
55     }
56    
57     }
58    
59     1;

  ViewVC Help
Powered by ViewVC 1.1.26