Skip to content

Instantly share code, notes, and snippets.

@shiba-yu36
Created November 28, 2010 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiba-yu36/718974 to your computer and use it in GitHub Desktop.
Save shiba-yu36/718974 to your computer and use it in GitHub Desktop.
自動refollowスクリプト
#!perl
use strict;
use warnings;
use Readonly;
use Net::Twitter::Lite;
Readonly my $following_count_limit => 10;
my $consumer_key = 'YOUR_CONSUMER_KEY';
my $consumer_secret = 'YOUR_CONSUMER_SECRET';
my $access_token = 'YOUR_ACCESS_TOKEN';
my $access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET';
my $twitter = Net::Twitter::Lite->new(
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
);
$twitter->access_token($access_token);
$twitter->access_token_secret($access_token_secret);
my $cursor = -1;
my $following_count_in_series = 0; # followerで何人連続followしているかを数えておく
FETCH_LOOP : while ($cursor != 0) {
my $followers = $twitter->followers({ cursor => $cursor });
$cursor = $followers->{next_cursor};
for my $follower (@{$followers->{users}}) {
if ($follower->{following}) {
$following_count_in_series++;
warn 'following before ', $follower->{screen_name};
}
else {
$following_count_in_series = 0;
$twitter->create_friend($follower->{screen_name});
warn 'follow ', $follower->{screen_name};
}
# 連続でフォローしている数がしきい値を超えたら
# これ以上フォローしていない人はいないとみなし、終了する
last FETCH_LOOP if $following_count_in_series >= $following_count_limit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment