How to Get Voting Lists with RubysteemCreated with Sketch.

in radiator •  2 years ago

Ever want to build a whitelist of accounts to vote on? This script will take a list of voters, get their latest history, and output a list of upvotes, downvotes, and unvotes.


If you're not into the command line, I've also updated my Ganymede project and added this functionality. To try this logic out yourself, browse to one of these ...

... then click the Upvotes or Downvotes tab.


As always, we use Radiator with 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 unique_votes.rb containing:

require 'rubygems'
require 'bundler/setup'

Bundler.require

puts "Usage: ruby #{__FILE__} <type: up | down | un | all> <voters>" and return if ARGV.empty?

api = Radiator::Api.new(url: 'https://this.piston.rocks:443')
#api = Radiator::Api.new(url: 'https://node.steem.ws:443')
type = ARGV[0].to_sym
voters = ARGV[1..-1]
votes = []

voters.each do |voter|
  response = api.get_account_votes(voter)
  next unless !!response.result
  
  votes += response.result.map do |vote|
    voted = vote.authorperm.split('/').first
    
    case type
    when :up; next unless vote.percent > 0
    when :down; next unless vote.percent < 0
    when :un; next unless vote.percent == 0
    end
    
    voted
  end
end

puts votes.compact.uniq

Then run it:

$ ruby unique_votes.rb up fyrstikken

The expected output will be something like this:

news-crypto
yoshinori
atiliog
toxichan
jmetroya
billykeed
kakradetome
mynameisricky
carrotliu
koskl
kingofcoin
noganoo
steempower
safar01
artem-sokoloff
montreal32
eliowilson
jgcastrillo19
brigen
wowpeach
alandesignart
lasseehlers
alwayssmile
fibra59
azra
justusagenstum
alfarisi
grossefreiheittv
michelle.gent
jamtaylor
.
.
.

The above example would result in 3946 unique results at the time of writing. You can also pass multiple voters, which will combine the results.

ruby

See my previous Ruby How To posts in: #radiator #ruby

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!