/[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 110 - (show annotations)
Wed Mar 14 20:02:19 2007 UTC (17 years, 1 month ago) by dpavlin
File size: 1559 byte(s)
another bunch of various tweaks, but Lucene still doesn't lock index right
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 base 'Jifty::Object';
9
10 use Data::Dump qw/dump/;
11
12 =head2 fetch
13
14 Grep::Source::Feed->fetch( $source_obj );
15
16 =cut
17
18 sub fetch {
19 my $self = shift;
20
21 my $parent = shift || $self->log->confess('no parent?');
22 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 $parent->save('feed.xml', $content);
33
34 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 $self->log->debug("getting ", scalar $xml_feed->entries, " entries from ", $xml_feed->format, " feed ", $xml_feed->title);
40
41 for my $entry ($xml_feed->entries) {
42
43 $parent->add_record(
44 in_feed => $feed,
45 title => $entry->title || $entry->link,
46 link => $entry->link,
47 content => $entry->content->body,
48 summary => $entry->summary->body,
49 category => $entry->category,
50 author => $entry->author,
51 issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S") : undef,
52 modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S") : undef,
53 );
54
55 }
56
57 }
58
59 1;

  ViewVC Help
Powered by ViewVC 1.1.26