create account

How to Write a Vote Bot in Ruby by inertia

View this thread on: hive.blogpeakd.comecency.com
· @inertia ·
$21.14
How to Write a Vote Bot in Ruby
Now that Radiator supports transaction signing, I thought I'd combine it with the existing streaming capability.  So this is a simple bot that mirrors other users and votes on the same things (posts and comments).  It only upvotes if the original vote is an upvote.

---

To use this [Radiator](https://steemit.com/steem/@inertia/radiator-steem-ruby-api-client) bot:

##### Linux

```bash
$ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
$ gem install bundler
$ bundle config git.allow_insecure true
```

##### macOS

```bash
$ 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:

```bash
$ mkdir radiator
$ cd radiator
```

Create a file named `Gemfile` containing:

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

Then run the command:

```bash
$ bundle install
```

Create a file named `tail_voters.rb` containing:

```ruby
require 'rubygems'
require 'bundler/setup'

Bundler.require

wif = 'Your Posting Wif'
voter = 'your-account'
list = ['inertia', 'fyrstikken']
url = 'https://steemd.steemit.com'
stream = Radiator::Stream.new(url: url)

puts "Watching for votes by: #{list}"

stream.operations do |operation|
  begin
    op_key = operation.keys.first
    op_value = operation.values.first

    print '.'

    next unless op_key == :vote
    next unless list.include? op_value.voter
    next unless op_value.weight > 0

    author = op_value.author
    permlink = op_value.permlink
    puts "\nVoting on: #{author}/#{permlink}"

    tx = Radiator::Transaction.new(wif: wif, url: url)
    vote = {
      type: :vote,
      voter: voter,
      author: author,
      permlink: permlink,
      weight: 10000
    }
    
    op = Radiator::Operation.new(vote)
    tx.operations << op
    tx.process(true)
  rescue => e
    puts e.inspect
  end
end
```

Then run it:

```bash
$ ruby tail_voters.rb
```

The above example would vote for anything `inertia` and `fyrstikken` vote for.

![ruby](http://www.steemimg.com/images/2016/08/24/1024px-Ruby_logo.svgdcc20.png)

See my previous Ruby How To posts in: [#radiator](https://steemit.com/created/radiator) [#ruby](https://steemit.com/created/ruby)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 105 others
properties (23)
authorinertia
permlinkhow-to-write-a-vote-bot-in-ruby
categoryradiator
json_metadata{"tags":["radiator","ruby","steem","howto","curation"],"image":["http://www.steemimg.com/images/2016/08/24/1024px-Ruby_logo.svgdcc20.png"],"links":["https://steemit.com/steem/@inertia/radiator-steem-ruby-api-client","https://steemit.com/created/radiator","https://steemit.com/created/ruby"],"app":"steemit/0.1","format":"markdown"}
created2017-02-26 07:36:30
last_update2017-02-26 07:36:30
depth0
children2
last_payout2017-03-29 12:33:03
cashout_time1969-12-31 23:59:59
total_payout_value20.848 HBD
curator_payout_value0.294 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,308
author_reputation346,568,901,399,561
root_title"How to Write a Vote Bot in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id2,595,809
net_rshares32,385,422,274,336
author_curate_reward""
vote details (169)
@abit ·
Good job. Bots are evils ;)
👍  
properties (23)
authorabit
permlinkre-inertia-how-to-write-a-vote-bot-in-ruby-20170226t220937098z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2017-02-26 22:10:15
last_update2017-02-26 22:10:15
depth1
children0
last_payout2017-03-29 12:33:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length27
author_reputation141,171,499,037,785
root_title"How to Write a Vote Bot in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,600,532
net_rshares22,102,692,262
author_curate_reward""
vote details (1)
@personz ·
Great to see more bot code open source 😆 

If you'd like to contribute this to the [Steem FOSSbot project](https://github.com/steem-fossbot), let me know, I would love to make you a collaborator, or "repost" this myself as a repo. 🙂
properties (22)
authorpersonz
permlinkre-inertia-how-to-write-a-vote-bot-in-ruby-20170226t140932820z
categoryradiator
json_metadata{"tags":["radiator"],"links":["https://github.com/steem-fossbot"],"app":"steemit/0.1"}
created2017-02-26 14:09:33
last_update2017-02-26 14:09:33
depth1
children0
last_payout2017-03-29 12:33:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length232
author_reputation42,452,361,038,560
root_title"How to Write a Vote Bot in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,597,473
net_rshares0