Plagger::Plugin::Subscription::Toranoanaã§metaã使ã£ã¦ã¿ã
ã©ãããä¸éã¯metaãã¼ã ãããã®ã§ã
- is_yaoi
- is_adult
ãtrue = "1", false = ""ã§{entry}->meta->{is_*}ã«å
¥ãã¦ã¿ããçå½å¤ã®è¡¨ç¾ã¯ããããããªãã1/0ã®æ¹ãèªç¶ãªãã ãããã¼ãã¼ã§ããã£ã¼ãã ãããXMLãããªãããã¼ããã¾ãPlaggerã§åãã°ããããis_adultãããã¯å¤¢ãããããã ããã¦ãä¸æ©å¯ãã¨metaæ±æãå¿é
ã«ãªã£ã¦ããããã¼ã§ãã©ããªãã ããã¼ãã¾ãæ°ã«ããªãäºã«ãããã
æ¥ä»ã¾ããã¯Plagger::Dateã使ãããã«ãããããã«ä»ã¾ã§ã®æ¥ä»è¨å®ï¼mmddï¼ã®ã»ãã«ãPPC::MelonBooksã®yyyy/mm/ddããã¨ãã®è¾ºãã®å端ãªè¡¨ç¾ã«å¯¾å¿ãã¤ã¾ãã¯((yyyy)?mmdd|(yyyy/)?mm/dd)ã¨ããæãã§ãã¨ãããããã£ããã©çµå±yesterdayã¨ã使ãããããªã£ã¦ãã¨ã§DateTime::Format::Natural::ENã使ã£ã¦ã¿ããã ãã©ããã¡ã®ç°å¢ã ã¨ä½éã£ã¦ãç¾å¨æå»ã帰ã£ã¦æ¥ããªã
ec% date && perl -MDateTime::Format::Natural::EN -e 'print DateTime::Format::Natural::EN->parse_datetime("yesterday")."\n"' æ¨ 10 26 04:20:58 JST 2006 2006-10-26T04:20:58
ãããªæããç ãã®ã§æ·±è¿½ãããªããã©ãã®ãã¡ç´ãã®ã ããããã¤ã¼ãã¦ã¼ã¶ãåå¨ãããã¨ãããããã«ãªã£ãã®ã§å¾ã§PODæ¸ãã¨ããå¯ãã
ã³ã¡ã³ãæ¬ã«ããããã¼ã«tagsã«ãã¡ã¿ãã¼ã¿å
¥ãã¦ã¿ãã18ç¦ãã©ããã¯å人çã«ãçµæ§ããã ãªããã¨PODæ¸ããã
module:è¡ã ãã§åããã¼ã«ãã¦ãã®ã ãã©ãããã©ã«ãå¤ã®æ±ããã¹ã£ã¦ãã®ã§ããã°ã
config.yaml
ä¾ãã°ç·æ§åãã¨ãå人ã ãã®ãã£ã¼ããã¤ãããªãã
- module: Subscription::Toranoana config: shop: - mailorder - aki1 - module: Filter::Rule rule: expression: (!$args->{entry}->meta->{is_yaoi} && $args->{entry}->meta->{is_adult})
ããããã¼ã¡ããç¨ãªãã
- module: Filter::Rule rule: expression: $args->{entry}->meta->{is_yaoi}
P/P/S/Toranoana.pm
ããã«ã¯Diffã ãã
@@ -8,6 +8,7 @@ use Plagger::Util; use Plagger::Feed; use Plagger::Entry; +use Plagger::Date; use URI; use HTML::TreeBuilder::XPath; @@ -41,15 +42,17 @@ my($self, $context, $shop) = @_; my @t = localtime(time); - my $day = $self->conf->{day} || sprintf("%02d%02d", $t[4]+1, $t[3]); + my $dt = $self->_datetime; + my $mmdd = $dt->strftime('%m%d'); + my $yyyymmdd = $dt->strftime('%Y%m%d'); my $booknodes = $self->_uri2nodes( - "http://www.toranoana.jp/shop/newka/${day}/${shop}_all.html", + "http://www.toranoana.jp/shop/newka/${mmdd}/${shop}_all.html", "//body/div[3]/table" ); my $feed = Plagger::Feed->new; - $feed->title("Toranoana\@$shop: $day"); + $feed->title("Toranoana\@$shop: $yyyymmdd"); for my $book (@$booknodes) { $self->_add_entry($context, $feed, { html => $book, @@ -63,17 +66,17 @@ my($self, $context) = @_; my @t = localtime(time); - my $day = $self->conf->{day} || sprintf("%02d%02d", $t[4]+1, $t[3]); - my $mon = substr($day, 0, 2); - my $year = 1900 + $t[5]; + my $dt = $self->_datetime; + my $day = $dt->strftime('%Y/%m/%Y%m%d'); + my $yyyymmdd = $dt->strftime('%Y%m%d'); my $booknodes = $self->_uri2nodes( - "http://www.toranoana.jp/cgi-bin/navi.cgi\?nvl=/mailorder/cot/newly/$year/$mon/$year$day.nvl\&n=1", + "http://www.toranoana.jp/cgi-bin/navi.cgi\?nvl=/mailorder/cot/newly/$day.nvl\&n=1", "//table" ); my $feed = Plagger::Feed->new; - $feed->title("Toranoana mailorder: $year$day"); + $feed->title("Toranoana mailorder: $yyyymmdd"); for my $book (@$booknodes) { $self->_add_entry($context, $feed, { html => $book, @@ -108,6 +111,7 @@ while (my ($key, $value) = each %$book_ref) { eval('$entry->'.$key.'($value)'); } + $feed->add_entry($entry); } } @@ -120,12 +124,7 @@ if (my @table = ($html =~ m|<td[^>]*>([^<]*)</td>|g)) { my $book_id = $table[0]; - if ($self->_is_yaoi($html, 'color\: \#FF99FF')) { - $context->log(info => "$book_id is yaoi"); - return; - } - - my $dir = join('/', ($book_id =~ /^(\d{2})(\d{4})(\d{2})(\d{2})/)) . $book_id; + my $dir = join('/', ($book_id =~ /^(\d{2})(\d{4})(\d{2})(\d{2})/) , $book_id); my $link = "http://www.toranoana.jp/mailorder/article/$dir.html"; my $result = { @@ -136,6 +135,9 @@ tags => $table[3] }; + $result->{meta}->{is_adult} = ($html =~ /color\: \#FF0000/) ? '1' : ''; + $result->{meta}->{is_yaoi} = ($html =~ /color\: \#FF99FF/) ? '1' : ''; + return $result; } } @@ -149,11 +151,6 @@ my $dir = $1; if ($dir) { - if ($self->_is_yaoi($html, 'navi_icon_bl\.gif')) { - $context->log(info => "$dir is yaoi"); - return; - } - my $link = "http://www.toranoana.jp/mailorder/article/$dir.html"; $html =~ /\>([^\<]+)\<\/a/m; @@ -161,31 +158,22 @@ my $result = { title => $1, link => $link, - body => _gen_body($dir, $link) + body => _gen_body($dir, $link), + meta => {}, }; - if ($html =~ /<td class\=\"td_block_no_color\">\s+([^<]*)<.*<td class\=\"td_block_color\">\s+([^<]*)</m) { + if ($html =~ /<td class\=\"td_block_no_color\">\s+([^<]*)<.*<td class\=\"td_block_color\">\s+([^<]*)</) { $result->{tags} = $1; $result->{author} = $2; } + $result->{meta}->{is_adult} = ($html =~ /navi_icon_18\.gif/) ? '1' : ''; + $result->{meta}->{is_yaoi} = ($html =~ /navi_icon_bl\.gif/) ? '1' : ''; + return $result; } } -sub _is_yaoi { - my ($self, $target, $regexp) = @_; - if ( - ($target =~ /$regexp/) - and ($self->conf->{yaoi_block}) - ) - { - return 1; - } - - return undef; -} - sub _gen_body { my ($dir, $link) = @_; @@ -197,5 +185,27 @@ return $result; } +sub _datetime { + my $self = shift; + my $day = $self->conf->{day}; + + my $dt = Plagger::Date->now; + return $dt unless ($day); + + if ($day =~ /^\d{4}(\d{4})?$/) { + if (length($day) == 4) { + $day = $dt->year.$day; + } + if (length($day) == 8) { + return Plagger::Date->strptime('%Y%m%d', $day); + } + } + elsif ($day =~ /^[\d\/]{10}$/) { + return Plagger::Date->strptime('%Y/%m/%d', $day); + } + + return Plagger::Date->parse("Natural::EN", $day); +} + 1;