How to List All Followers in Ruby

in #radiator8 years ago

Here's how to use Radiator to get a list of all followers on a specified account. The only prerequisite is having bundler. You can get bundler with this command:

$ gem install bundler

I've tested it on various versions of ruby. The oldest one I got it to work was:

ruby 2.0.0p645 (2015-04-13 revision 50299) [x86_64-darwin14.4.0]

First, make a project folder:

$ mkdir radiator
$ cd radiator

Create a file named Gemfile containing:

source 'https://rubygems.org'
gem 'radiator', github: 'inertia186/radiator'

Then run the command:

$ bundle install

Create a file named all_followers.rb containing:

require 'rubygems'
require 'bundler/setup'

Bundler.require

puts "Usage: ruby #{__FILE__} [account]" and retun if ARGV.empty?

api = Radiator::FollowApi.new(url: 'https://node.steem.ws:443')
followers = []
count = -1

until count == followers.size
  count = followers.size
  response = api.get_followers(ARGV.first, followers.last, 'blog', 100)
  followers += response.result.map(&:follower)
  followers = followers.uniq
  sleep 1
end

puts followers

Then run it:

$ ruby all_followers.rb ned

ruby

Sort:  

Very cool.

Thanks. Bookmarking. Cashtags: $b.ruby $b.followers $b.dev $b.follow_api $b.steem

I prefer Bashtags: #!ruby #!followers #!dev #!follow_api #!steem =D