otsune's SnakeOil RSSフィード

python -c "print''.join([chr(x) for x in 111&1101,110+~-~11,10^11*11,110+~-~11,-~101,-~11^11*11,~-110,111&11*11,11+11+10,11|~-0110,1-~11^11*11,10^11*11,-~11^11*11,110,101])"

2007-05-13

Publish::Buzzurl試し(メモ)

| Publish::Buzzurl試し(メモ) - otsune's SnakeOil  を含むブックマーク はてなブックマーク - Publish::Buzzurl試し(メモ) - otsune's SnakeOil  Publish::Buzzurl試し(メモ) - otsune's SnakeOil  のブックマークコメント

Publish::Livedoorベースに修正してみた。まだメモ品質。

no titleAPIの解説。

追記:CPANWebService::BuzzurlAPIがあるから、それ使った方が全然良いな。検索で「ECNavi」でしか探してなかったから見つけられなかった……

package Plagger::Plugin::Publish::Buzzurl;
use strict;
use base qw( Plagger::Plugin );

use Encode;
use Time::HiRes qw(sleep);
use URI;
use JSON::Syck;
use Plagger::Mechanize;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'publish.entry' => \&add_entry,
        'publish.init'  => \&initialize,
    );
}

sub initialize {
    my $self = shift;
    unless ($self->{mech}) {
        my $mech = Plagger::Mechanize->new;
        $mech->agent_alias('Windows IE 6');
        $mech->quiet(1);
        $self->{mech} = $mech;
    }
    $self->login_ecnavi;
}

sub add_entry {
    my ($self, $context, $args) = @_;

    my @tags = @{$args->{entry}->tags};
    my $tag_string = @tags ? join(' ', @tags) : ''; # TODO: max 8 tags

    my $summary;
    if ($self->conf->{post_body}) {
        $summary = encode('utf-8', $args->{entry}->body_text); # xxx should be summary
    }

    my $uri = URI->new('https://buzzurl.jp/posts/add/v1');
    $uri->query_form(
        url     => $args->{entry}->link,
        title   => encode('utf-8', $args->{entry}->title),
        keyword => encode('utf-8', $tag_string),
        comment => $summary,
    );

    my $add_url = $uri->as_string;
    my $res = eval { $self->{mech}->get($add_url) };
    if ($res && $res->is_success) {
        my @result = JSON::Syck::Load($res->content);
        if ($result->{status} eq 'fail') {
            $context->log(info => "can't submit: " . $result->{reason} . " " . $args->{entry}->link);
        } else {
            $context->log(info => "Post entry success.");
        }
    } else {
       $context->log(info => "fail to clip $add_url HTTP Status: " . $res->code);
    }
 
    my $sleeping_time = $self->conf->{interval} || 3;
    $context->log(info => "sleep $sleeping_time.");
    sleep( $sleeping_time );
}

sub login_ecnavi {
    my $self = shift;
    unless ($self->conf->{ecnavi_mail} && $self->conf->{password}) {
        Plagger->context->log(error => 'set your ecnavi_mail and password before login.');
    }
    unless ($self->_has_buzzurl_account) {
        Plagger->context->log(error => 'register to Buzzurl before using this module.');
    }
    my $res = $self->{mech}->get('https://buzzurl.jp/config/login');
    $self->{mech}->submit_form(
        form_number => 3,
        fields => {
            mail => $self->conf->{ecnavi_mail},
            pass => $self->conf->{password},
        },
    );
    # XXX login checking (WWW::Mechanize->uri() doesn't work correct).
    $self->{mech}->get('https://buzzurl.jp/config/login?done=http%3A%2F%2Fbuzzurl.jp%2Fconfig%2Fadd%2F');
    $self->{_logged_in} = $self->{mech}->uri =~ m{^http://buzzurl.jp/config/add/} ? 1 : 0;
    unless ($self->{_logged_in}) {
        Plagger->context->log(error => "failed to login to Buzzurl.");
    }
}

sub _has_clip_account {
    my $self = shift;
    my $myclip_url = sprintf('http://buzzurl.jp/user/%s', $self->conf->{buzzurl_id});
    my $res = $self->{mech}->get($myclip_url);
    return $res->is_success ? 1 : 0;
}

1;

__END__

=head1 NAME

Plagger::Plugin::Publish::Buzzurl - Post to Buzzurl automatically

=head1 SYNOPSIS

  - module: Publish::Buzzurl
    config:
      ecnavi_mail: your-ECnavi-mailaddress
      buzzurl_id: your-username
      password: your-password
      interval: 2
      post_body: 1

=head1 DESCRIPTION

This plugin automatically posts feed updates to Buzzurl
L<http://buzzurl.jp/>. It supports automatic tagging as well. It
might be handy for synchronizing delicious feeds into Buzzurl.

=head1 AUTHOR

Masafumi Otsune

=head1 SEE ALSO

L<Plagger>, L<Plagger::Plugin::Publish::LivedoorClip>, L<Plagger::Mechanize>,
L<http://labs.ecnavi.jp/developer/buzzurl/api/>

=cut

s_nobus_nobu2007/05/13 12:26これ使えませんかね?
http://search.cpan.org/~holly/WebService-BuzzurlAPI-0.02/lib/WebService/BuzzurlAPI.pm

トラックバック - http://subtech.g.hatena.ne.jp/otsune/20070513