11 |
use base qw/Grep::Action Jifty::Action/; |
use base qw/Grep::Action Jifty::Action/; |
12 |
|
|
13 |
use XML::Feed; |
use XML::Feed; |
14 |
|
use LWP::UserAgent; |
15 |
|
|
16 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
17 |
|
|
38 |
}]; |
}]; |
39 |
}; |
}; |
40 |
|
|
41 |
|
param item_fragment => |
42 |
|
label is 'Show', |
43 |
|
render as 'select', |
44 |
|
valid are qw/result result_short/, |
45 |
|
available are qw/result result_short/; |
46 |
|
|
47 |
}; |
}; |
48 |
|
|
49 |
=head2 take_action |
=head2 take_action |
72 |
|
|
73 |
my $uri = $feed->uri; |
my $uri = $feed->uri; |
74 |
if ($uri =~ m/%s/) { |
if ($uri =~ m/%s/) { |
75 |
$uri = sprintf( $uri, $self->argument_value('q') ); |
$uri = $feed->search_uri( $self->argument_value('q') ); |
76 |
Jifty->log->info("Searching ", $feed->title, " at $uri"); |
Jifty->log->info("Searching ", $feed->title, " at $uri"); |
77 |
} else { |
} else { |
78 |
Jifty->log->info("Fetching ", $feed->title, " at $uri"); |
Jifty->log->info("Fetching ", $feed->title, " at $uri"); |
79 |
} |
} |
80 |
|
|
81 |
my $xml_feed = XML::Feed->parse( URI->new($uri) ) |
my $ua = LWP::UserAgent->new; |
82 |
or die XML::Feed->errstr; |
$ua->default_header( 'Cookie' => $feed->cookie ); |
83 |
|
my $r = $ua->get( $uri ); |
84 |
|
die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success ); |
85 |
|
|
86 |
|
my $content = $r->content; |
87 |
|
|
88 |
|
die "No content returned from $uri" unless length( $content ) > 1; |
89 |
|
|
90 |
warn "fetching ", $xml_feed->title, "\n"; |
my $xml_feed = XML::Feed->parse( \$content ) |
91 |
|
or die $feed->title, " returned ", XML::Feed->errstr, " for $uri\n"; |
92 |
|
|
93 |
|
warn "getting entries from ", $xml_feed->title, "\n"; |
94 |
|
|
95 |
my @items; |
my @items; |
96 |
|
|
109 |
modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef, |
modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef, |
110 |
); |
); |
111 |
|
|
112 |
die "can't create item from entry ", dump( $entry ) unless ( $i->id ); |
if ( $i->id ) { |
113 |
|
push @items, $i; |
114 |
|
|
115 |
push @items, $i; |
# Grep::Event::Result->new( $i )->publish; |
116 |
|
|
117 |
# Grep::Event::Result->new( $i )->publish; |
Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) ); |
118 |
|
} else { |
119 |
|
warn "can't create item from entry ", dump( $entry ) unless ( $i->id ); |
120 |
|
} |
121 |
|
|
|
Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) ); |
|
122 |
} |
} |
123 |
|
|
124 |
if ( @items ) { |
if ( @items ) { |
132 |
|
|
133 |
} else { |
} else { |
134 |
|
|
135 |
$self->result->message( 'No results found' ); |
$self->result->error( 'No results found' ); |
|
|
|
|
# with default sticky_on_failure, this will keep form data |
|
|
$self->result->failure( 1 ); |
|
|
|
|
136 |
return 0; |
return 0; |
137 |
|
|
138 |
} |
} |
139 |
} |
} |
140 |
|
|