From: mitty Date: Mon, 4 Oct 2010 10:01:27 +0000 (+0000) Subject: * add trace outputs for debugging X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=f0a098030f12c444ad00e67b1745892016e5b206;p=lab.git * add trace outputs for debugging git-svn-id: https://lab.mitty.jp/svn/lab/trunk/twitter@59 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- diff --git a/twitterbot.pl b/twitterbot.pl index ccd2c5a..575ca65 100755 --- a/twitterbot.pl +++ b/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->{results}); 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; }