Skip to content

Instantly share code, notes, and snippets.

@rsnorman
Last active November 26, 2016 19:04
Show Gist options
  • Save rsnorman/8d9701835f7fef4be0c2d9e0bbeba365 to your computer and use it in GitHub Desktop.
Save rsnorman/8d9701835f7fef4be0c2d9e0bbeba365 to your computer and use it in GitHub Desktop.
Creates follows
# Create Twitter followers
# Class: NewTwitterFriendAccumulator
File.open(Rails.root.join('db/follower_ids.txt'), 'wb') {|f| WistfulIndie::Twitter::Client.client.follower_ids.each { |fid| f << "#{fid}\n" } }
File.open(Rails.root.join('db/friend_ids.txt'), 'wb') {|f| WistfulIndie::Twitter::Client.client.friend_ids.each { |fid| f << "#{fid}\n" } }
# Class: TwitterFriendsFollower
File.read(Rails.root.join('db/friend_ids.txt')).split("\n").each { |id| TwitterFollow.create(twitter_id: id) }
# Class: TwitterFollowCreator
TwitterFollow.all.each { |tf| tf.update(screen_name: WistfulIndie::Twitter::Client.client.user(tf.twitter_id.to_i).screen_name) }
follower_ids = File.read(Rails.root.join('db/follower_ids.txt')).split("\n")
follower_ids.map { |fid| TwitterFollow.find_by(twitter_id: fid) }.compact.each { |tf| tf.update(is_friend: true) }
Artist.all.each { |a| tf = TwitterFollow.find_by(screen_name: a.twitter_screen_name); tf && tf.update(artist_id: a.id) }
# Unfollow ungrateful Twitter friends
TwitterFollow.ungrateful.each do |tf|
begin
WistfulIndie::Twitter::Client.client.unfollow(tf.twitter_id.to_i)
tf.destroy
puts "Unfollowed the ungrateful bastard: #{tf.screen_name}"
rescue Twitter::Error::TooManyRequests
puts 'Hit rate limit, waiting 15 minutes before trying again'
sleep 15.minutes
end
end
Artist.where.not(id: TwitterFollow.artist.pluck(:artist_id)).each do |a|
begin
WistfulIndie::Twitter::Client.client.follow(a.twitter_screen_name)
puts "Followed #{a.name} at #{a.twitter_screen_name}"
rescue Twitter::Error::NotFound
puts "Could not find Twitter user for #{a.twitter_screen_name}"
rescue Twitter::Error::TooManyRequests
puts 'Hit rate limit, waiting 15 minutes before trying again'
sleep 15.minutes
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment