いろいろ試して、なんとか当面の自分の目的には使えそうになったので、公開。(前回最終的に、とか書いたけど、まだまだ最終になりそうにないので、今回は最終版とか言わない)
まずは、CustomFeed::Mixi
便利便利!?
まずは、CustomFeed::Mixi
*** /usr/local/lib/perl5/site_perl/5.8.8/Plagger/Plugin/CustomFeed/Mixi.pm.ORIG Fri Jan 5 23:14:14 2007 --- /usr/local/lib/perl5/site_perl/5.8.8/Plagger/Plugin/CustomFeed/Mixi.pm Sun Jan 7 20:40:08 2007 *************** *** 48,53 **** --- 48,62 ---- get_list => 'parse_show_calendar', get_detail => 'get_view_event', }, + Bbs => { + start_url => 'http://mixi.jp/new_bbs.pl', + title => 'コミュニティ最新書き込み', + get_list => 'parse_new_bbs', + get_detail => 'dummy', + get_detail_bbs => 'get_view_bbs', + get_detail_event => 'get_view_event', + get_detail_enquete => 'get_view_enquete', + }, }; sub plugin_id { *************** *** 134,139 **** --- 143,149 ---- my $i = 0; my $blocked = 0; + my $item; for my $msg (@msgs) { next if $type eq 'FriendDiary' and not $msg->{image}; # external blog last if $i++ >= $items; *************** *** 143,148 **** --- 153,161 ---- $entry->link($msg->{link}); $entry->author( decode('euc-jp', $msg->{name}) ); $entry->date( Plagger::Date->parse($format, $msg->{time}) ); + if ($entry->date) { + $entry->date->set_time_zone('Asia/Tokyo'); + } if ($self->conf->{show_icon} && !$blocked && defined $MAP->{$type}->{icon_re}) { my $owner_id = ($msg->{link} =~ $MAP->{$type}->{icon_re})[0]; *************** *** 170,182 **** } } ! if ($self->conf->{fetch_body} && !$blocked && $msg->{link} =~ /view_/ && defined $MAP->{$type}->{get_detail}) { $context->log(info => "Fetch body from $msg->{link}"); ! my $item = $self->cache->get_callback( "item-$msg->{link}", sub { Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 ); ! my $meth = $MAP->{$type}->{get_detail}; my($item) = $self->{mixi}->$meth($msg->{link}); if ($meth eq 'get_view_diary') { --- 183,199 ---- } } ! $item = 0; ! ! if ($self->conf->{fetch_body} && !$blocked && $msg->{link} !~ /view_enquete/ &&$msg->{link} =~ /view_/ && defined $MAP->{$type}->{get_detail}) { $context->log(info => "Fetch body from $msg->{link}"); ! $item = $self->cache->get_callback( "item-$msg->{link}", sub { Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 ); ! # my $meth = $MAP->{$type}->{get_detail}; ! my $meth = get_meth($MAP->{$type}, $msg->{link}); ! my($item) = $self->{mixi}->$meth($msg->{link}); if ($meth eq 'get_view_diary') { *************** *** 189,195 **** if ($item) { my $body = decode('euc-jp', $item->{description}); $body =~ s!(\r\n?|\n)!<br />!g; ! for my $image (@{ $item->{images} }) { $body .= qq(<div><a href="$image->{link}"><img src="$image->{thumb_link}" style="border:0" /></a></div>); my $enclosure = Plagger::Enclosure->new; $enclosure->url( URI->new($image->{thumb_link}) ); --- 206,213 ---- if ($item) { my $body = decode('euc-jp', $item->{description}); $body =~ s!(\r\n?|\n)!<br />!g; ! my $image; ! for $image (@{ $item->{images} }) { $body .= qq(<div><a href="$image->{link}"><img src="$image->{thumb_link}" style="border:0" /></a></div>); my $enclosure = Plagger::Enclosure->new; $enclosure->url( URI->new($image->{thumb_link}) ); *************** *** 197,205 **** --- 215,234 ---- $enclosure->is_inline(1); $entry->add_enclosure($enclosure); } + if ($image = $item->{image}) { + $body .= qq(<div><a href="$image"><img src="$image" style="border:0" /></a></div>); + my $enclosure = Plagger::Enclosure->new; + $enclosure->url( URI->new($image) ); + $enclosure->auto_set_type; + $enclosure->is_inline(1); + $entry->add_enclosure($enclosure); + } $entry->body($body); $entry->date( Plagger::Date->parse($format, $item->{time}) ); + if ($entry->date) { + $entry->date->set_time_zone('Asia/Tokyo'); + } } else { $context->log(warn => "Fetch body failed. You might be blocked?"); $blocked++; *************** *** 207,212 **** --- 236,244 ---- } $feed->add_entry($entry); + if ($self->conf->{fetch_body} && $item) { + add_comments($feed, $item); + } } $context->update->add($feed); *************** *** 221,226 **** --- 253,301 ---- } return \@images; + } + sub get_meth { + my($type, $link) = @_; + + my $meth = ""; + if ($link =~ /view_bbs/) { + $meth = $type->{get_detail_bbs}; + } elsif ($link =~ /view_event/) { + $meth = $type->{get_detail_event}; + } elsif ($link =~ /view_enquete/) { + $meth = $type->{get_detail_enquete}; + } else { + $meth = $type->{get_detail}; + } + return $meth; + } + + sub add_comments { + my ($feed, $item) = @_; + my $format = DateTime::Format::Strptime->new(pattern => '%Y/%m/%d %H:%M'); + if ($item->{'comments'}) { + for my $comment (@{$item->{'comments'}}) { + my $entry = Plagger::Entry->new; + $entry->title(decode('euc-jp', $item->{'subject'}) . ": " . $comment->{'number'}); + $entry->link($item->{'link'}); + $entry->author( decode('euc-jp', $comment->{'name'}) ); + $entry->date( Plagger::Date->parse($format, $comment->{'time'}) ); + if ($entry->date) { + $entry->date->set_time_zone('Asia/Tokyo'); + } + my $body = decode('euc-jp', $comment->{'description'}); + for my $image (@{ $comment->{images} }) { + $body .= qq(<div><a href="$image->{link}"><img src="$image->{thumb_link}" style="border:0" /></a></div>); + my $enclosure = Plagger::Enclosure->new; + $enclosure->url( URI->new($image->{thumb_link}) ); + $enclosure->auto_set_type; + $enclosure->is_inline(1); + $entry->add_enclosure($enclosure); + } + $entry->body( $body ); + $feed->add_entry($entry); + } + } } 1;変更箇所は、以下の通り。
- feed_type: Bbs の追加
- Plagger::Entry の date に、timezoneを設定。(これをやらないと、module: Freshのruleがずれてしまう)
- feed_type: Messageでのimageの取得(未確認)
*** /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mixi.pm.ORIG Sat Jan 6 21:54:02 2007 --- /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mixi.pm Sun Jan 7 21:52:17 2007 *************** *** 1426,1431 **** --- 1426,1432 ---- my $re_subj = '<td bgcolor="#fff4e0"> (.+?)</td>'; my $re_desc = '</table>(.+?)</td>'; my $re_c_date = '<td rowspan="2" width="110" bgcolor="#f2ddb7" align="center" nowrap>\n(\d{4})年(\d{2})月(\d{2})日<br>\n(\d{1,2}):(\d{2})'; + my $re_c_no = '<b>(.*?[0-9]+?)</b>'; my $re_c_desc = '<td class="h120">(.+?)\n</td>'; my $re_link = '<a href="?(.+?)"?>(.*?)<\/a>'; if ($content =~ s/<!-- TOPIC: start -->.*?${re_date}.*?${re_subj}.*?${re_link}(.*?)${re_desc}(.*?)$//is) { *************** *** 1436,1445 **** next unless ($image =~ /<a [^<>]*'show_picture.pl\?img_src=(.*?)'[^<>]*><img src=([^ ]*) border=0>/); push(@{$item->{'images'}}, {'link' => $self->absolute_url($1, $base), 'thumb_link' => $self->absolute_url($2, $base)}); } ! while ($comm =~ s/.*?${re_c_date}.*?${re_link}.*?${re_c_desc}.*?<\/table>//is){ ! my ($time, $link, $name, $desc) = (sprintf('%04d/%02d/%02d %02d:%02d', $1,$2,$3,$4,$5), $6, $7, $8); ! ($name, $desc) = map { s/[\r\n]+//g; s/<br>/\n/g; $_ = $self->rewrite($_); } ($name, $desc); ! push(@{$item->{'comments'}}, {'time' => $time, 'link' => $self->absolute_url($link, $base), 'name' => $name, 'description' => $desc}); } push(@items, $item); } --- 1437,1450 ---- next unless ($image =~ /<a [^<>]*'show_picture.pl\?img_src=(.*?)'[^<>]*><img src=([^ ]*) border=0>/); push(@{$item->{'images'}}, {'link' => $self->absolute_url($1, $base), 'thumb_link' => $self->absolute_url($2, $base)}); } ! while ($comm =~ s/.*?${re_c_date}.*?${re_c_no}.*?${re_link}.*?${re_c_desc}.*?<\/table>//is){ ! my ($time, $number, $link, $name, $desc) = (sprintf('%04d/%02d/%02d %02d:%02d', $1,$2,$3,$4,$5), $6, $7, $8, $9); ! # ($name, $desc) = map { s/[\r\n]+//g; s/<br>/\n/g; $_ = $self->rewrite($_); } ($name, $desc); ! push(@{$item->{'comments'}}, {'time' => $time, 'link' => $self->absolute_url($link, $base), 'name' => $name, 'description' => $desc, 'number' => $number, 'images' => []}); ! foreach my $image ($desc =~ /<td width=130[^<>]*>(.*?)<\/td>/g) { ! next unless ($image =~ /<img src=([^ ]*) border=0>/); ! push(@{$item->{'comments'}->{'images'}}, {'link' => $self->absolute_url($1, $base), 'thumb_link' => $self->absolute_url($1, $base)}); ! } } push(@items, $item); } *************** *** 1582,1588 **** my $label_time = "(?:\Q日 付\E|\Q日 付\E)"; my $label_name = "(?:\Q差出人\E|\Q宛 先\E)"; my $label_subj = "(?:\Q件 名\E|\Q件 名\E)"; ! my $time = sprintf('%04d/%02d/%02d %02d:%02d', $1, $2, $3, $4, $5) if ($content =~ /<$td>$s<font(?:$attr)*>$label_time<\/font>$s:$s(\d{4})年(\d{2})月(\d{2})日$s(\d{2}):(\d{2})<\/td>/is); my $subj = $self->rewrite($1) if ($content =~ /<$td>$s<font(?:$attr)*>$label_subj<\/font>$s:$s($str)<\/td>/is); my $desc = $self->rewrite($1) if ($content =~ /<td(?:$attr)*CLASS=h120(?:$attr)*>$s($str)<\/td>/is); my $image = $self->absolute_url($1, $base) if ($content =~ /<$td><a(?:$attr)*><img(?:$attr)*src=["']?([^"'\s<>]+)["'](?:$attr)*><\/a><\/td>/is); --- 1587,1593 ---- my $label_time = "(?:\Q日 付\E|\Q日 付\E)"; my $label_name = "(?:\Q差出人\E|\Q宛 先\E)"; my $label_subj = "(?:\Q件 名\E|\Q件 名\E)"; ! my $time = sprintf('%04d/%02d/%02d %02d:%02d', $1, $2, $3, $4, $5) if ($content =~ /<$td>$s<font(?:$attr)*>$label_time<\/font>$s:$s(\d{4})年(\d{2})月(\d{2})日$s(\d{2})時(\d{2})分$s<\/td>/is); my $subj = $self->rewrite($1) if ($content =~ /<$td>$s<font(?:$attr)*>$label_subj<\/font>$s:$s($str)<\/td>/is); my $desc = $self->rewrite($1) if ($content =~ /<td(?:$attr)*CLASS=h120(?:$attr)*>$s($str)<\/td>/is); my $image = $self->absolute_url($1, $base) if ($content =~ /<$td><a(?:$attr)*><img(?:$attr)*src=["']?([^"'\s<>]+)["'](?:$attr)*><\/a><\/td>/is);変更点は、
- parse_view_bbs で、コメント番号を取るように
- parse_view_bbs で、コメントのimagesを取るように
- parse_view_bbs で、コメントのbrタグを改行に変えないように
global: timezone: Asia/Tokyo assets_path: /usr/local/share/Plagger/assets plugins: - module: Publish::Gmail rule: - module: Rating rate: '>= 0' config: mailto: gmailのアドレス@gmail.com mailfrom: 差出人のアドレス mailroute: via: smtp host: localhost attach_enclosures: 1 - module: Filter::Rule rule: - module: Fresh mtime: path: ホームディレクトリ/.plagger/tstamp autoupdate: 1 - module: Filter::FetchEnclosure config: dir: ホームディレクトリ/.plagger/enclosures - module: CustomFeed::Mixi config: email: mixiに登録したのメールアドレス password: mixiのパスワード fetch_body: 1 fetch_body_interval: 1.5 fetch_items: 25 show_icon: 0 feed_type: - Message - RecentComment - Log - FriendDiary - Bbs
- Filter::FetchEnclosureを追加
- Publish::Gmailのconfigに、attach_enclosures: 1 を追加
便利便利!?
カテゴリ
Linuxトラックバック(0)
このブログ記事を参照しているブログ一覧: mixiのコミュニティ新着の取得(その3)
このブログ記事に対するトラックバックURL: https://www.wizard-limit.net/cgi-bin/mt/mt-tb.cgi/1122
コメントする