Personal tools

mixiとblogをそのまま同期させると、del.icio.usのdaily postがmixiでは役立たずになってウザそうだからどうにかする

written by nobu on

mixiにそのまま投稿しちゃうと、本来リンクじゃないと困るものが、ただのテキストになってしまうわけで。どっちみち携帯から見てる人には無用なエントリになっちゃうし、いっそのことmixiには投稿しないようにしようと。一番てっとり早いのはP::P::MixiDiary.pm内で、単純にif文でほげほげすることなんだけど。ちょっと気が向いたのでplugin初挑戦してみた。

package Plagger::Plugin::Filter::StripDeliciousDailyPost;
use strict;
use base qw( Plagger::Plugin );

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'update.entry.fixup' => \&filter,
    );
}

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

    my $title = $args->{entry}->title;
    for my $entry ($args->{feed}->entries) {
        if ($entry->title =~ /^links for \d{4}-\d{2}-\d{2}$/i) {
            $context->log(info => "Delete Delicious daily post entry " . $entry->link);
            $args->{feed}->delete_entry($entry);
        }
    }
}

1;
__END__

やはりperlは書き慣れんな。yamlを以下のようにして動作確認。

plugins:
- module: Subscription::Config
    config:
     feed:
        - url: http://nobu666.com/rss?feed=rss2
- module: Filter::Rule
    rule:
     module: Deduped
     path: /tmp/blog2mixi.tmp
     compare_body: 1
- module: Filter::Reverse
- module: Filter::FindEnclosures
- module: Filter::FetchEnclosure
    config:
     dir: /tmp/fetch-image
- module: Filter::FormatText
- module: Filter::EntryFullText
- module: Filter::StripDeliciousDailyPost
- module: Publish::MixiDiary
    config:
     username: メールアドレス
     password: パスワード
     interval: 10
     originally_link: 1

,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>