Plaggerで物件探し
夏頃に引っ越ししようと思って、いろんな不動産サイトを探しているのですが、フィードに対応してなかったり、通知機能がしょぼかったりするので、Plaggerで無理矢理対応させてしまおうかと。
とりあえず、目白商事という不動産サイトの検索結果をRSSフィードにするプラグインを書いてみました。ここから検索した結果ページのURLをYAMLで設定します。
以下スクリプトと設定ファイル
Plagger/Plugin/CustomFeed/MejiroShoji.pm
package Plagger::Plugin::CustomFeed::MejiroShoji; use strict; use warnings; use base qw( Plagger::Plugin ); use URI; use Web::Scraper; sub register { my($self, $context) = @_; $context->register_hook( $self, 'subscription.load' => \&load, ); } sub load { my($self, $context) = @_; my $feed = Plagger::Feed->new(); $feed->aggregator(sub { $self->aggregate(@_) }); $context->subscription->add($feed); } sub aggregate { my($self, $context, $args) = @_; my $uri = URI->new($self->conf->{uri}); $context->log(info => $uri); my $entry_scraper = scraper { process '/tr', 'body' => 'TEXT', process '/tr/td[2]', 'id' => [ 'HTML' , sub { @_ = split /<br \/>/, $_; shift; }], process '/tr/td[2]/a', 'title' => 'TEXT' , process '/tr/td[2]/a', 'link' => '@href' , process '/tr/td[3]', 'date' => [ 'HTML' , sub { @_ = split /<br \/>/, $_; pop; }] }; my $scraper = scraper { process '//div[@id="mainContents"]//table[@class!="search_form_tbl"]/tr[count(td) >= 1]', 'data[]' => $entry_scraper; }; my $result = $scraper->scrape($uri); my $feed = Plagger::Feed->new(); $feed->type('MejiroShoji'); $feed->title('目白商事の物件'); $feed->link($uri); foreach my $line (@{$result->{data}}) { my $entry = Plagger::Entry->new(); my $dt = eval { Plagger::Date->parse_dwim($line->{date}) }; $entry->date($dt) if $dt; $entry->body($line->{body}); $entry->author($line->{title}); $entry->title($line->{title}); $entry->link($line->{link}); $feed->add_entry($entry); } $context->update->add($feed); } 1; __END__
config.yaml
plugins: - module: CustomFeed::MejiroShoji config: uri: http://www.real-mejiro.co.jp/search/index.php?line_near_line[]=1&place_city=&place_town=&rent_min=0&rent_max=1&monopoly_area=&article_type=%E6%8C%87%E5%AE%9A%E3%81%AA%E3%81%97&line_time=0&mode=40&submit2.x=169&submit2.y=3&submit2=%E8%A9%B3%E7%B4%B0%E6%A4%9C%E7%B4%A2 - module: Publish::Feed config: format: RSS dir: /var/www/html/moving-feed filename: MejiroShoji.rss
この調子でフォ●ントとか他のサイトも全部フィードとかメール通知とかに対応させていって、そのうち「WEB2.0時代の家探し」と題して書籍化する予定です(嘘)。
Googleストリートビューで、家の周りの様子とかもすぐ分かるしね。便利な世の中です。。