mixiで外部ブログを使っている場合の運用法を Plaggerを使って簡単化してみた。
A FreeBSD GIMPer mixiと外部ブログの様な運用をするにあたって問題になるのが手作業でやるのが非常に面倒臭いということ。 そこでこれが便利になるようなツールが必要になる。
実現方法案としては
- blogの投稿時にhookしてmixiの投稿アクションを呼び出す。
- 外部のソフトからblog, mixiの両方の投稿アクションを呼び出す。
- blogのRSSの内容をmixiに記事ごとにpostする。
しかし、自分は目の前にPCがないときにはモブログで更新するのでこれを考慮しなくてはならない。 それを考慮した手法として適しているのは上記の一番最後の、RSS経由でmixiにpostする方法である。 なぜならばこの方法ならば端末からのpostは一度で済むからである。
ということでRSSを調理してそれをmixiに投稿する仕組みを考えてみて、たしか"ぷらっがー"とかいうのが…とひらめいたので"plagger"で検索してみたらやっぱりそういうものだったようなのでそれを使ってみることにした。
というわけで
- Plagger - Trac
- mixi日記にplaggerから投稿する - plus ultra blog
- Piece of a Puzzle - Weblog - P::P::Publish::MixiDiary #2
- P::P::Publish::MixiDiaryに「interval」を追加 - cameraLady
- [plagger]feed to mixi recipe - HisasueVox
FreeBSDのportsからplaggerをいれてみたが追加のpluginの作法とか考えるのがめんどくさかったのでuser directoryに
svn co http://svn.bulknews.net/repos/plagger/trunk/plagger
で引っ張ってきてその下でごそごそやった。
ports://www/p5-WWW-Mixi ( Perlモジュール/WWW::Mixi - Walrus, Digit.) が必要なのでこれもいれる。
MixiDiary.pm はこんな感じにした
package Plagger::Plugin::Publish::MixiDiary;
use strict;
use warnings;
use base qw ( Plagger::Plugin );
use WWW::Mixi;
use Encode;
use Time::HiRes qw(sleep);
sub register {
my($self, $context) = @_;
$context->register_hook(
$self,
'publish.init' => \&initialize,
'publish.entry' => \&post_diary,
);
}
sub initialize {
my($self, $context, $args) = @_;
my $cookie_jar = $self->cookie_jar;
if (ref($cookie_jar) ne 'HTTP::Cookies') {
$self->conf->{username} ||= 'email@example.com',
$self->conf->{password} ||= 'p4ssw0rd',
}
$self->{mixi} = WWW::Mixi->new(
$self->conf->{username},
$self->conf->{password},
-log => 0,
);
$self->{mixi}->cookie_jar($cookie_jar);
unless ($self->{mixi}->login) {
$context->log(error => "Login failed.");
} else {
$context->log(info => "Login Successed.");
}
}
sub post_diary {
my($self, $context, $args) = @_;
my $e = $args->{entry};
my $title = $e->title;
my $body = $e->body_text;
my $linkurl = $e->link;
my $memo = "-------------------------------\n originally posted
on Your Blog\n";
$body = $body."\n\n".$memo.$linkurl; # $body plus quotation
my @images;
if ($e->has_enclosure) {
for my $enclosure (grep { defined $_->url
&& $_->is_inline
&& ($_->url =~ /.*\.jpg$/) } $e->enclosure) {
push(@images, $enclosure->local_path);
}
}
my %diary = (
diary_title => encode('euc-jp', $title),
diary_body => encode('euc-jp', $body),
photo1 => shift(@images),
photo2 => shift(@images),
photo3 => shift(@images),
);
my $sleeping_time = $self->conf->{interval} || 3;
if ($self->{mixi}->get_add_diary_confirm(%diary)) {
$context->log(info => "Making diary succeeded.");
} else {
$context->log(error => "Making diary failed.");
}
}
1;
__END__
=hea1 NAME
Plagger::Plugin::Publish::MixiDiary - publish mixi diary
=head1 SYNOPSIS
- module: Publish::MixiDiary
config:
username: email@example.com
password: p4ssw0rd
interval: 10
=head1 DESCRIPTION
This plugin posts entry to mixi diary.
=over 4
=item username, password
Your e-mail and password for logging in mixi
=back
=cut
=head1 AUTHOR
Tsuyoshi Maekawa
=head1 SEE ALSO
L<Plagger>, L<WWW::Mixi>, L<http://mixi.jp/>
=cut
config.yaml のほうはこんな感じ。
global:
timezone: Asia/Tokyo
log:
level: info
plugins:
- module: Subscription::Config
config:
feed:
- url: http://www.example.com/?xml
- module: Filter::Rule
rule:
module: Deduped
path: /home/user/tmp/plagger/cache_rule/feed2mixidiary.tmp
compare_body: 1
- module: Filter::Reverse
- module: Filter::FindEnclosures
- module: Filter::FetchEnclosure
config:
dir: /home/user/tmp/plagger/fetch_images
- module: Publish::MixiDiary
config:
username: email@example.com
password: p4passw0rd
interval: 10
Reverse.pm のコードはnirvashの日記 - [sbm] del.icio.us to hatebuから
あと、自分のところでは文字化けしなかったけど、文字化けする場合は[plagger]feed to mixi recipe - HisasueVoxが参考になるだろう。
あとは自宅鯖などでcronで回しておけば良いだろう。
現在自分はとりあえず
#!/bin/sh
while :
do
./mixidiary/plagger/plagger -c ./mixidiary/config.yaml
sleep 3600
done
の様なshell script を書いてこれで様子を見ている。
トラックバックURL↓
http://youcharmanums.blog2.fc2.com/tb.php/478-e0a558a2
[日記]Twitterをmixi日記に送りたくて
悪戦苦闘して、やっとこさWinndows環境に Perl 5.8.8.817 Plagger 0.7.17 をインストールが済んだ。 そして、Muibrog - 2007-04-24にある 1日のTwitterをまとめてMixi日記になげるレシピを導入した。 AssembleEntries.pm、yamlを丸写しで作成し、 MixiDiary.pmもA FreeBS
2007.10.05 21:41 | 活動記録





