ãããPaggerã§ã
config.yaml
plugins: - module: Subscription::Config config: feed: http://localhost/ - module: CustomFeed::AmazonSearch config: developer_token: XXXXXXXXXX keywords: - ããããã - Perl mode: books-jp locale: jp - module: Publish::iCal config: dir: /Users/user/Sites/plagger/amazon/ filename: books.ics
Subscription::Configã¯ããã¼ã
CustomFeed::AmazonSearch
Perlã®ç·´ç¿ã«æ¸ãã¦ã¿ããç·´ç¿ã¨è¨ãã¤ã¤è²ã ããå æ¸ã
package Plagger::Plugin::CustomFeed::AmazonSearch; use strict; use base qw( Plagger::Plugin ); use Net::Amazon; use Net::Amazon::Request::Keyword; sub register { my($self, $context) = @_; $context->register_hook( $self, 'customfeed.handle' => \&aggregate, ); } sub aggregate { my($self, $context, $args) = @_; my $feed = Plagger::Feed->new; for my $keyword (@{$self->conf->{keywords}}) { $self->_search($feed, $context, $keyword); } $context->update->add($feed); } sub _search { my($self, $feed, $context, $keyword) = @_; my $ua = Net::Amazon->new( token => $self->conf->{developer_token}, locale => $self->conf->{locale}, ); my $req = Net::Amazon::Request::Keyword->new( keyword => $keyword, mode => $self->conf->{mode}, sort => "daterank", ); my $res = $ua->request($req); if($res->is_error) { $context->log(error => $res->message); return; } my $dt = Plagger::Date->now; $dt->subtract(months => 1); for my $prop ($res->properties) { my $e = Plagger::Entry->new; $e->title($prop->ProductName); $e->body($prop->ProductDescription); my $date = Plagger::Date->strptime("%Y/%m/%d", $prop->ReleaseDate); $date = Plagger::Date->strptime("%Y/%m", $prop->ReleaseDate) unless $date; $e->date($date); my $d = $date - $dt; next if $d->is_negative; $feed->add_entry($e); } } 1;
è¨å®ã§ã«ãã´ãª(mode)ãè¨å®ã§ãã風ã§å®ã¯sortã®å¼æ°ãªãããæ¸ç±ã«ãã対å¿ãã¦ããªãã£ããããã
å®è¡çµæ
å®è¡ããã¨keywordsã§æå®ãããã¼ã¯ã¼ãã§æ¤ç´¢ããçµæãicsãã¡ã¤ã«ã¨ãã¦åºåããã¾ããã¨ãããããçºå£²æ¥ãä»æ¥ã®æ¥ä»ããä¸ã¶æ以ä¸åã®ãã®ã¯çãããã«ãªã£ã¦ãã¾ããçºå£²æ¥ãæã¾ã§ãããªããã¨ãããã¿ãããªã®ã§ãããã¡ãã£ã¨ç·©ãããæ¹ãããã®ãããããªã(è¨å®ã§ããã¹ãã)ã
åºåãããicsãã¡ã¤ã«ãiCalãªããã§èªãã¨ä»¥ä¸ã®ãããªæãã«ã
試ãã¦ãªããã©Google Calenderã§ãèªããã®ããªã
ããã¾ã§æ¸ãã¦
CustomFeedãããªãã¦Subscription::AmazonSearchã¨ãã¦æ¸ãã¹ãã ã£ãããããªããã¨æã£ããâ¦â¦å¾ã§è¦ç´ããã