/[Grep]/lib/Grep/Action/Fetch.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/Action/Fetch.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (hide annotations)
Sat Feb 17 18:06:42 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 1933 byte(s)
store actual content body, not class name :-)
1 dpavlin 3 use strict;
2     use warnings;
3    
4     =head1 NAME
5    
6     Grep::Action::Fetch
7    
8     =cut
9    
10     package Grep::Action::Fetch;
11     use base qw/Grep::Action Jifty::Action/;
12    
13     use XML::Feed;
14    
15     use Data::Dump qw/dump/;
16    
17     use Jifty::Param::Schema;
18     use Jifty::Action schema {
19    
20     param q =>
21     type is 'text',
22     label is 'Search for',
23     hint is 'enter few words to search for';
24    
25     param feed =>
26     label is 'From feed',
27     render as 'combobox',
28     available are defer {
29     my $feeds = Grep::Model::FeedCollection->new;
30     $feeds->order_by({ column => 'title', order => 'ASC' });
31     $feeds->unlimit;
32     warn "feeds ", $feeds->build_select_query;
33     [{
34     display_from => 'title',
35     value_from => 'id',
36     collection => $feeds,
37     }];
38     };
39    
40     };
41    
42     =head2 take_action
43    
44     =cut
45    
46     sub take_action {
47     my $self = shift;
48    
49     # Custom action code
50    
51     my $feed = Grep::Model::Feed->new();
52     my $feed_id = $self->argument_value('feed');
53    
54     if (! $feed_id) {
55     $self->result->message("Need feed ID");
56     return 0;
57     }
58    
59     $feed->load_by_cols( id => $feed_id );
60    
61     if (! $feed->id) {
62     $self->result->message("Can't fetch feed $feed_id");
63     return 0;
64     }
65    
66     Jifty->log->info("Fetching ", $feed->title, " from ", $feed->uri);
67    
68     my $xml_feed = XML::Feed->parse( URI->new( $feed->uri ) )
69     or die XML::Feed->errstr;
70    
71     warn "fetching ", $xml_feed->title, "\n";
72     for my $entry ($xml_feed->entries) {
73     my $i = Grep::Model::Item->new();
74    
75     $i->load_or_create(
76     in_feed => $feed,
77     title => $entry->title,
78     link => $entry->link,
79 dpavlin 5 content => $entry->content->body,
80     summary => $entry->summary->body,
81 dpavlin 3 category => $entry->category,
82     author => $entry->author,
83     issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S %z") : undef,
84     modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef,
85     );
86 dpavlin 5
87     Jifty->log->debug("entry = ",dump( $entry ) );
88 dpavlin 3 }
89    
90     $self->result->message('Success') if not $self->result->failure;
91    
92     return 1;
93     }
94    
95     1;
96    

  ViewVC Help
Powered by ViewVC 1.1.26