Skip to content

Instantly share code, notes, and snippets.

@sugyan sugyan/zenra.pl
Created Jul 23, 2010

Embed
What would you like to do?
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Config::Pit;
use Net::Twitter;
use WebService::Simple;
use YAML;
my $config = pit_get("twitter.com", require => {
consumer_key => '',
consumer_secret => '',
access_token => '',
access_token_secret => '',
});
my $yahoo = WebService::Simple->new(
base_url => "http://jlp.yahooapis.jp/MAService/V1/parse",
param => {
appid => pit_get("yahoo.co.jp"),
}
);
my $nt = Net::Twitter->new(
traits => [qw/API::REST OAuth/],
%$config,
);
my @replies = ();
for my $status (@{ $nt->mentions }) {
my $zenrized_text = zenrize($status->{text});
next unless $zenrized_text;
$status->{text} = $zenrized_text;
push @replies, $status;
}
my $reply = $replies[rand @replies];
my $reply_text = $reply->{text};
warn Dump $nt->update({
status => "\@$reply->{user}{screen_name} $reply_text;",
in_reply_to_status_id => $reply->{id},
});
sub zenrize {
my $text = shift;
my $res = $yahoo->get({ sentence => $text })->parse_response;
my $result = '';
my $zenrized;
for my $word ( @{ $res->{ma_result}{word_list}{word} } ) {
if ($word->{pos} eq '動詞') {
$zenrized = 1;
$result .= '全裸で';
}
$result .= ref $word->{surface} ? ' ' : $word->{surface};
}
return $zenrized ? $result : undef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.