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

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

so Hatena fixed the form name duplicate problem

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