/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (show annotations)
Fri Feb 23 21:16:44 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 1396 byte(s)
added hooks to Grep::Source->save to keep useful snippets of html in /tmp/grep (if writable)
1 # 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 $parent->save('feed.xml');
31
32 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 warn "getting entries from ", $xml_feed->title, "\n";
38
39 for my $entry ($xml_feed->entries) {
40
41 $parent->add_record(
42 in_feed => $feed,
43 title => $entry->title,
44 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