root/trunk/plagger/lib/Plagger/Plugin/Subscription/HatenaRSS.pm

Revision 115 (checked in by miyagawa, 14 years ago)

oooops

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Subscription::HatenaRSS;
2 use strict;
3 use base qw( Plagger::Plugin::Subscription::OPML );
4
5 use WWW::Mechanize;
6
7 sub register {
8     my($self, $context) = @_;
9
10     $context->register_hook(
11         $self,
12         'subscription.load' => \&load,
13     );
14 }
15
16 sub load {
17     my($self, $context) = @_;
18
19     my $username = $self->conf->{username}
20         or $context->error('username is missing');
21
22     my $start = "https://www.hatena.ne.jp/login?backurl=http%3A%2F%2Fr.hatena.ne.jp%2F";
23
24     # TODO: we should save the cookie and reuse
25     my $mech = WWW::Mechanize->new;
26     $mech->get($start);
27
28     $mech->submit_form(
29         fields => {
30             key      => $username,
31             password => $self->conf->{password},
32         },
33     );
34
35     if ( $mech->content =~ m!<div class="erorr">! ) {
36         $context->log(error => "Login to HatenaRSS failed.");
37     }
38
39     $context->log(info => "Login to HatenaRSS succeed.");
40
41     $mech->get("http://r.hatena.ne.jp/$username/config");
42     $mech->submit_form(form_name => 'opmlexport');
43
44     my $opml = $mech->content;
45     $context->log(info => "Exported OPML: " . length($opml) . " bytes");
46
47     $self->load_opml($context, \$opml);
48 }
49
50 1;
51
52 __END__
53
54 =head1 NAME
55
56 Plagger::Plugin::Subscrption::HatenaRSS - HatenaRSS Subscription via OPML
57
58 =head1 SYNOPSIS
59
60   - module: Subscription::HatenaRSS
61     config:
62       username: example
63       password: xxxxxxxx
64
65 =head1 DESCRIPTION
66
67 This plugin creates Subscription by fetching Hatena RSS
68 L<http://r.hatena.ne.jp> OPML by HTTP. Since Hatena RSS OPML export
69 requires login state, it uses WWW::Mechanize module to emulate the
70 browser's login authentication procedure.
71
72 =head1 AUTHOR
73
74 Tatsuhiko Miyagawa
75
76 =head1 SEE ALSO
77
78 L<Plagger>, L<Plagger::Plugin::Subscription::OPML>, L<WWW::Mechanize>
79
80 =cut
Note: See TracBrowser for help on using the browser.