/[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 102 - (hide annotations)
Sun Mar 4 22:16:23 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 1430 byte(s)
removed all debug warn(s) or move them to $self->log->debug
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     use Data::Dump qw/dump/;
9    
10     =head2 fetch
11    
12     Grep::Source::Feed->fetch( $source );
13    
14     =cut
15    
16     sub fetch {
17     my $self = shift;
18    
19     my $parent = shift;
20     my ($feed,$uri) = ($parent->feed, $parent->uri);
21     die "no uri" unless ($uri);
22     die "feed is not a Grep::Model::Feed but ", ref $feed unless $feed->isa('Grep::Model::Feed');
23    
24     my $ua = LWP::UserAgent->new;
25     $ua->default_header( 'Cookie' => $feed->cookie );
26     my $r = $ua->get( $uri );
27     die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success );
28     my $content = $r->content;
29    
30 dpavlin 99 $parent->save('feed.xml', $content);
31 dpavlin 86
32 dpavlin 72 die "No content returned from $uri\n" unless length( $content ) > 1;
33    
34     my $xml_feed = XML::Feed->parse( \$content )
35     or die $feed->title, " returned ", XML::Feed->errstr, "\n";
36    
37 dpavlin 102 $self->log->debug("getting entries from ", $xml_feed->title);
38 dpavlin 72
39     for my $entry ($xml_feed->entries) {
40    
41     $parent->add_record(
42     in_feed => $feed,
43 dpavlin 99 title => $entry->title || $entry->link,
44 dpavlin 72 link => $entry->link,
45     content => $entry->content->body,
46     summary => $entry->summary->body,
47     category => $entry->category,
48     author => $entry->author,
49     issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S") : undef,
50     modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S") : undef,
51     );
52    
53     }
54    
55     }
56    
57     1;

  ViewVC Help
Powered by ViewVC 1.1.26