projects
/
lab.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* change structure of return value from or_search, mentions_ids
[lab.git]
/
twitter
/
twitterbot.pl
diff --git
a/twitter/twitterbot.pl
b/twitter/twitterbot.pl
index
575ca65
..
249c1bc
100755
(executable)
--- a/
twitter/twitterbot.pl
+++ b/
twitter/twitterbot.pl
@@
-33,31
+33,32
@@
if (! $bot->authorized) {
die "$0: this client is not yet authorized.\n";
}
die "$0: this client is not yet authorized.\n";
}
-my %tweets;
+my $tweets = {};
my $tweet;
$tweet = or_search($bot, $conf->{hashtag}, $stat->{search});
if ($tweet) {
my $tweet;
$tweet = or_search($bot, $conf->{hashtag}, $stat->{search});
if ($tweet) {
- %tweets = (%tweets, %$tweet);
+ %$tweets = (%$tweets, %$tweet);
}
$tweet = mentions_ids($bot, $stat->{mention});
if ($tweet) {
}
$tweet = mentions_ids($bot, $stat->{mention});
if ($tweet) {
- %tweets = (%tweets, %$tweet);
+ %$tweets = (%$tweets, %$tweet);
}
}
-foreach my $id (sort keys %tweets) {
- if ($tweets{$id} eq 'retweet') {
+foreach my $id (sort keys %$tweets) {
+ # $tweets->{$id}{type} eq 'search' => found by search API
+ # eq 'mention' => found by mention API
+ if ($tweets->{$id}{type} eq 'retweet') {
next;
}
DEBUG or sleep($conf->{sleep});
next;
}
DEBUG or sleep($conf->{sleep});
- # retweet found tweet
- # $tweets->{$id} eq 'search' => found by search API
- # eq 'mention' => found by mention API
+
+ # do retweet found tweets
my $res;
eval {
DEBUG or $res = $bot->retweet($id);
my $res;
eval {
DEBUG or $res = $bot->retweet($id);
- DEBUG and warn "retweet($id) => ", Dumper($tweets{$id});
+ DEBUG and warn "retweet($id) => ", Dumper($tweets->{$id});
};
if ($@) {
evalrescue($@);
};
if ($@) {
evalrescue($@);
@@
-65,10
+66,10
@@
foreach my $id (sort keys %tweets) {
next;
}
next;
}
- $stat->{$tweets{$id}} = $id;
+ $stat->{$tweets->{$id}{type}} = $id;
}
}
-if (%tweets) {
+if ($tweets) {
# save last status to yaml file
DEBUG or YAML::Tiny::DumpFile("$Bin/status.yml", $stat);
DEBUG and warn "status.yml => ", Dumper($stat);
# save last status to yaml file
DEBUG or YAML::Tiny::DumpFile("$Bin/status.yml", $stat);
DEBUG and warn "status.yml => ", Dumper($stat);
@@
-142,14
+143,14
@@
sub or_search {
);
}
if ($res->{results}) {
);
}
if ($res->{results}) {
- VERBOSE and warn Dumper($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}) {
- $ids->{$tweet->{id}} = 'retweet';
+ $ids->{$tweet->{id}}{type} = 'retweet';
}
else {
}
else {
- $ids->{$tweet->{id}} = 'search';
+ $ids->{$tweet->{id}}{type} = 'search';
}
VERBOSE and warn Dumper($res);
}
}
VERBOSE and warn Dumper($res);
}
@@
-188,7
+189,11
@@
sub mentions_ids {
my $ids = {};
if ($res && @{$res}) {
$ids = {
my $ids = {};
if ($res && @{$res}) {
$ids = {
- map { $_->{id} => 'mention' } @{$res}
+ map {
+ $_->{id} => {
+ type => 'mention',
+ }
+ } @{$res}
};
}
};
}