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";
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($@);
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);
}
$key = $word;
}
}
+ DEBUG and warn "searching '$key'";
my $res;
my $ids = {};
);
}
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}) {
else {
$ids->{$tweet->{id}} = 'search';
}
+ VERBOSE and warn Dumper($res);
}
}
};
evalrescue($@);
}
+ DEBUG and warn "search result => ", Dumper($ids);
return $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;
}