| 1 | package Plagger::Plugin::CustomFeed::Frepa::RecentComment; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use HTML::Entities; | ||
| 5 | use Encode; | ||
| 6 | use URI; | ||
| 7 | |||
| 8 | sub title { 'フレパのあなたの日記へのコメント' } | ||
| 9 | |||
| 10 | sub start_url { 'http://www.frepa.livedoor.com/blog/recent_comment' } | ||
| 11 | |||
| 12 | sub get_list { | ||
| 13 | my($self, $mech, $plugin) = @_; | ||
| 14 | |||
| 15 | my @msgs = (); | ||
| 16 | $mech->get($self->start_url); | ||
| 17 | return @msgs unless $mech->success; | ||
| 18 | |||
| 19 | my $html = decode('euc-jp', $mech->content); | ||
| 20 | my $reg = decode('utf-8', $self->_list_regexp); | ||
| 21 | while ($html =~ m|$reg|igs) { | ||
| 22 | my $time = "$1/$2/$3 $4:$5"; | ||
| 23 | my ($link, $subject, $user_link, $name) = | ||
| 24 | (decode_entities($6), decode_entities($7), decode_entities($8), decode_entities($9)); | ||
| 25 | my $uri = URI->new_abs($link, $self->start_url); | ||
| 26 | $link = $uri->as_string; | ||
| 27 | |||
| 28 | # your post doesn't link to your profile, ick | ||
| 29 | if ($user_link =~ m!www\.frepa\.livedoor\.com/$!) { | ||
| 30 | $user_link = "http://frepa.livedoor.com/" . $plugin->conf->{livedoor_id} . "/"; | ||
| 31 | } | ||
| 32 | |||
| 33 | push(@msgs, +{ | ||
| 34 | user_link => $user_link, | ||
| 35 | link => $link, | ||
| 36 | subject => $subject, | ||
| 37 | name => $name, | ||
| 38 | time => $time, | ||
| 39 | }); | ||
| 40 | } | ||
| 41 | return @msgs; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub _list_regexp { | ||
| 45 | return <<'RE'; | ||
| 46 | <tr> | ||
| 47 | <th>(\d\d\d\d)\.(\d\d)\.(\d\d) (\d\d):(\d\d)</th> | ||
| 48 | <td><a href="([^"]+?)">(.+?)</a>\(<a href="([^"]+?)">(.+?)</a>\)</td> | ||
| 49 | </tr> | ||
| 50 | RE | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | __END__ |