Skip to content

Instantly share code, notes, and snippets.

@tai-cha
Created March 16, 2019 17:42
Show Gist options
  • Save tai-cha/7dc4457cd4e4e048968d39f9e8d040ad to your computer and use it in GitHub Desktop.
Save tai-cha/7dc4457cd4e4e048968d39f9e8d040ad to your computer and use it in GitHub Desktop.
ツイートid入れるとfavRTしたフォロワーを抽出するやつ
require 'twitter'
require 'net/http'
require 'json'
configFile = open('config.json') do |io|
JSON.load(io)
end
@client = Twitter::REST::Client.new do |config|
config.consumer_key = configFile['CK']
config.consumer_secret = configFile['CS']
config.access_token = configFile['Token']
config.access_token_secret = configFile['Secret']
end
MY_ID = configFile['my_id']
puts MY_ID.to_i
tweet_id = ""
def get_id_of_user_liked_post(tweet_id)
json_data = Net::HTTP.get(URI.parse('https://twitter.com/i/activity/favorited_popup?id=' + tweet_id))
found_ids = json_data.scan(/data-user-id=\\"+\d+/)
found_ids.each{|str| str.slice!(/data-user-id=\\\"+/)}
found_ids = found_ids.map(&:to_i)
unique_ids = found_ids.uniq
return unique_ids
end
loop do
puts "数字でツイートidを入力してください"
tweet_id = STDIN.readline
break if tweet_id =~ /^[0-9]+$/
end
retweeters = @client.retweeters_of(tweet_id,options={})
favoriters_id = get_id_of_user_liked_post(tweet_id)
retweeters_ids = []
retweeters.each do |user|
retweeters_ids.push user.id
end
if !favoriters_id.nil?
followers = @client.follower_ids(options={ :count => 5000 }).take(5000)
fav_rt_followers = retweeters_ids & favoriters_id & followers
if !(fav_rt_followers.nil? || fav_rt_followers == [])
puts fav_rt_followers.to_s
fav_rt_followers_info = @client.friendships(fav_rt_followers)
screen_names = fav_rt_followers_info.map{|info| info.screen_name}
puts screen_names
else
puts "fav_rt_followersがnil" if fav_rt_followers.nil?
puts "条件に当てはまる人はいませんでした" if fav_rt_followers == []
end
else
puts "ファボられ取得エラー"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment