projects
/
lab.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* fix typo
[lab.git]
/
twitter
/
twitterbot.pl
diff --git
a/twitter/twitterbot.pl
b/twitter/twitterbot.pl
index
ccd2c5a
..
d93e023
100755
(executable)
--- a/
twitter/twitterbot.pl
+++ b/
twitter/twitterbot.pl
@@
-13,6
+13,12
@@
use Net::Twitter::Lite;
use FindBin qw($Bin);
use YAML::Tiny;
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";
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;
}
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 {
# 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 ($@) {
evalrescue($@);
@@
-63,7
+70,8
@@
foreach my $id (sort keys %tweets) {
if (%tweets) {
# save last status to yaml file
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;
}
}
$key = $word;
}
}
+ DEBUG and warn "searching '$key'";
my $res;
my $ids = {};
my $res;
my $ids = {};
@@
-133,6
+142,7
@@
sub or_search {
);
}
if ($res->{results}) {
);
}
if ($res->{results}) {
+ VERBOSE and warn Dumper($res);
foreach my $tweet (@{$res->{results}}) {
my $res = $bot->show_status($tweet->{id});
if ($res->{retweeted_status}) {
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';
}
else {
$ids->{$tweet->{id}} = 'search';
}
+ VERBOSE and warn Dumper($res);
}
}
};
}
}
};
@@
-148,6
+159,7
@@
sub or_search {
evalrescue($@);
}
evalrescue($@);
}
+ DEBUG and warn "search result => ", Dumper($ids);
return $ids;
}
return $ids;
}
@@
-167,18
+179,20
@@
sub mentions_ids {
since_id => $since_id,
}
);
since_id => $since_id,
}
);
+ VERBOSE and warn Dumper($res);
};
if ($@) {
evalrescue($@);
}
};
if ($@) {
evalrescue($@);
}
- my $ids;
+ my $ids = {};
if ($res && @{$res}) {
$ids = {
map { $_->{id} => 'mention' } @{$res}
};
}
if ($res && @{$res}) {
$ids = {
map { $_->{id} => 'mention' } @{$res}
};
}
+ DEBUG and warn "mentions result => ", Dumper($ids);
return $ids;
}
return $ids;
}