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

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

Subscription::HatenaRSS now uses public OPML URL of HatenaRSS, and uses new Cookies sharing feature if available.

  • 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 Plagger::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 $mech = Plagger::Mechanize->new(cookie_jar => $self->cookie_jar);
23     $mech->get("http://r.hatena.ne.jp/$username/opml");
24
25     if ($mech->content !~ /<opml version/) {
26         $mech->get("https://www.hatena.ne.jp/login?backurl=http%3A%2F%2Fr.hatena.ne.jp%2F");
27         $mech->submit_form(
28             fields => {
29                 key      => $username,
30                 password => $self->conf->{password},
31             },
32         );
33
34         if ( $mech->content =~ m!<div class="error">! ) {
35             $context->log(error => "Login to HatenaRSS failed.");
36             return;
37         }
38     }
39
40     $context->log(info => "Login to HatenaRSS succeed.");
41
42     my $opml = $mech->content;
43     $context->log(info => "Exported OPML: " . length($opml) . " bytes");
44
45     $self->load_opml($context, \$opml);
46 }
47
48 1;
49
50 __END__
51
52 =head1 NAME
53
54 Plagger::Plugin::Subscription::HatenaRSS - HatenaRSS Subscription via OPML
55
56 =head1 SYNOPSIS
57
58   - module: Subscription::HatenaRSS
59     config:
60       username: example
61
62 =head1 DESCRIPTION
63
64 This plugin creates Subscription by fetching Hatena RSS
65 L<http://r.hatena.ne.jp> OPML by HTTP.
66
67 If your OPML is shared public (which is default), you don't have to
68 pass password to the config. Also, even if you OPML is private, you
69 can share Cookies with your favorite browser like Firefox, using
70
71   global:
72     user_agent:
73       cookies: /path/to/cookies.txt
74
75 so that you don't have to pass password to the config, again.
76
77 =head1 AUTHOR
78
79 Tatsuhiko Miyagawa
80
81 =head1 SEE ALSO
82
83 L<Plagger>, L<Plagger::Plugin::Subscription::OPML>, L<WWW::Mechanize>
84
85 =cut
Note: See TracBrowser for help on using the browser.