X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=twitter%2Ftwitterbot.pl;h=d93e023a697590ceaff8f88c34b271a20d1a99ea;hb=7e20eed62f390a5e39bcd48accd0e4023c0f8328;hp=ccd2c5aa58ef1989e22152d00c5ce4292ec5c3fa;hpb=35889d4eb83a3569fbcc4c7b4792656f000d1ac8;p=lab.git diff --git a/twitter/twitterbot.pl b/twitter/twitterbot.pl index ccd2c5a..d93e023 100755 --- a/twitter/twitterbot.pl +++ b/twitter/twitterbot.pl @@ -13,6 +13,12 @@ use Net::Twitter::Lite; use FindBin qw($Bin); use YAML::Tiny; +sub VERBOSE () { $ARGV[0] eq 'verbose' }; +sub DEBUG () { VERBOSE or $ARGV[0] eq 'debug' }; +use Data::Dumper; + +DEBUG and warn "$0: debug mode"; + my $conf = loadconf("$Bin/config.yml"); if (! defined $conf) { die "$0: cannot parse config file.\n"; @@ -44,13 +50,14 @@ foreach my $id (sort keys %tweets) { if ($tweets{$id} eq 'retweet') { next; } - sleep($conf->{sleep}); + DEBUG or sleep($conf->{sleep}); # retweet found tweet # $tweets->{$id} eq 'search' => found by search API # eq 'mention' => found by mention API my $res; eval { - $res = $bot->retweet($id); + DEBUG or $res = $bot->retweet($id); + DEBUG and warn "retweet($id) => ", Dumper($tweets{$id}); }; if ($@) { evalrescue($@); @@ -63,7 +70,8 @@ foreach my $id (sort keys %tweets) { if (%tweets) { # save last status to yaml file - YAML::Tiny::DumpFile("$Bin/status.yml", $stat); + DEBUG or YAML::Tiny::DumpFile("$Bin/status.yml", $stat); + DEBUG and warn "status.yml => ", Dumper($stat); } @@ -120,6 +128,7 @@ sub or_search { $key = $word; } } + DEBUG and warn "searching '$key'"; my $res; my $ids = {}; @@ -133,6 +142,7 @@ sub or_search { ); } if ($res->{results}) { + VERBOSE and warn Dumper($res); foreach my $tweet (@{$res->{results}}) { my $res = $bot->show_status($tweet->{id}); if ($res->{retweeted_status}) { @@ -141,6 +151,7 @@ sub or_search { else { $ids->{$tweet->{id}} = 'search'; } + VERBOSE and warn Dumper($res); } } }; @@ -148,6 +159,7 @@ sub or_search { evalrescue($@); } + DEBUG and warn "search result => ", Dumper($ids); return $ids; } @@ -167,18 +179,20 @@ sub mentions_ids { since_id => $since_id, } ); + VERBOSE and warn Dumper($res); }; if ($@) { evalrescue($@); } - my $ids; + my $ids = {}; if ($res && @{$res}) { $ids = { map { $_->{id} => 'mention' } @{$res} }; } + DEBUG and warn "mentions result => ", Dumper($ids); return $ids; }