Skip to content

Instantly share code, notes, and snippets.

@hiroxto
Last active September 28, 2018 13:18
Show Gist options
  • Save hiroxto/b2cf15bfddeca7af0bf57881684d6d32 to your computer and use it in GitHub Desktop.
Save hiroxto/b2cf15bfddeca7af0bf57881684d6d32 to your computer and use it in GitHub Desktop.
"statuses/home_timeline"の代替になるリストを作る。
# 複数アカウントで作れる "hiroto-k/alt-tl" を作ったのでそちらを参照。
# https://github.com/hiroto-k/alt-tl
require 'twitter'
require 'pp'
config = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: '',
}
# リストのID。Integerで指定。
list_id = nil
client = Twitter::REST::Client.new(config)
puts 'Get current members.'
members = client
.list_members(list_id, count: 5000)
.attrs[:users]
.map { |user|
user[:id]
}
puts 'Get current friends.'
friend = client
.friend_ids(count: 5000)
.attrs[:ids]
add_accounts = friend - members
remove_accounts = members - friend
puts 'Adds'
pp add_accounts
add_accounts.each_slice(100) do |user_ids|
client.add_list_members(list_id, user_ids)
end
puts 'Removes'
pp remove_accounts
remove_accounts.each_slice(100) do |user_ids|
client.remove_list_members(list_id, user_ids)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment