Skip to content

Instantly share code, notes, and snippets.

@naniwaKun
Last active August 23, 2017 08:39
Show Gist options
  • Save naniwaKun/20a7a22f508e5991361fe5936ff0fc86 to your computer and use it in GitHub Desktop.
Save naniwaKun/20a7a22f508e5991361fe5936ff0fc86 to your computer and use it in GitHub Desktop.
大量にフォロバしてしまったアラブ人をブロックしてブロック解除する。 ref: http://qiita.com/naniwaKun/items/5c2582f32c7116ae89c9
require "twitter"
require 'json'
USERNAME = "********"
client = Twitter::REST::Client.new do |config|
config.consumer_key = "********"
config.consumer_secret = "********"
config.access_token = "********"
config.access_token_secret = "********"
end
follower_ids = client.follower_ids(USERNAME).to_a
begin
followers = follower_ids.each_slice(100).to_a.inject ([]) do |users, ids|
users.concat(client.users(ids))
end
followers.each_with_index{ |user|
profile = user.name + user.description
regex = /[\p{Han}\p{Hiragana}\p{Katakana},.、。ー・]+/
japanese_arr = profile.scan(regex)
if (japanese_arr.empty?)
client.block(user.screen_name)
end
}
rescue Twitter::Error::TooManyRequests => error
sleep error.rate_limit.reset_in
retry
end
require "twitter"
require 'json'
USERNAME = "********"
client = Twitter::REST::Client.new do |config|
config.consumer_key = "********"
config.consumer_secret = "********"
config.access_token = "********"
config.access_token_secret = "********"
end
blocked_ids = client.blocked_ids(USERNAME).to_a
begin
blocked_list = blocked_ids.each_slice(100).to_a.inject ([]) do |users, ids|
users.concat(client.users(ids))
end
blocked_list.each_with_index{ |user|
profile = user.name + user.description
regex = /[\p{Han}\p{Hiragana}\p{Katakana},.、。ー・]+/
japanese_arr = profile.scan(regex)
if (japanese_arr.empty?)
client.unblock(user.screen_name)
end
}
rescue Twitter::Error::TooManyRequests => error
sleep error.rate_limit.reset_in
retry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment