Using the official steem-python to make a timing robot that can steadily claim the rewards

in STEEM CN/中文last year (edited)

Target:

  1. Be able to work normally in all kinds of bad network environment;
  2. Claim the rewards regularly every 30 minutes

0.jpeg

Because Steem official API node https://api.steemit.com cannot be accessed for various reasons, and other third-party API nodes also have various conditions. Therefore, robust robots should dynamically find available API nodes in these API nodes.

Demo Bot(auto_claim_bot.py):

import steembase
import steem
from pick import pick
from steem.steemd import Steemd
from steem.account import Account
from steem.amount import Amount
from steem.instance import set_shared_steemd_instance
from steem.blockchain import Blockchain

steemd_nodes = [
    'https://anyx.io',
    'https://steemd.minnowsupportproject.org',
    'https://rpc.esteem.app',
    'https://api.steemit.com',
    'https://api.steem.house',
    'https://gtg.steem.house:8090',
    'https://appbasetest.timcliff.com',
]

set_shared_steemd_instance(Steemd(nodes=steemd_nodes))

# username = input('Enter username: ')
username = 'dappcoder'
# post_key = input('Enter private POST key: ')
post_key = '5JzkkkkkK3ZN'

# connect node
client = steem.Steem(nodes=steemd_nodes, keys=[post_key])

# get account reward balances
userinfo = client.get_account(username)
print('userinfo:', userinfo)

if(userinfo is None):
    print('Oops. Looks like user ' + username +
          ' doesn\'t exist on this chain!')
    exit()

reward_steem = userinfo['reward_steem_balance']
reward_sbd = userinfo['reward_sbd_balance']
reward_sp = userinfo['reward_vesting_steem']
reward_vests = userinfo['reward_vesting_balance']

print('Reward Balances:' + '\n' +
      'STEEM: ' + reward_steem + '\n' +
      'SBD: ' + reward_sbd + '\n' +
      'STEEM POWER: ' + reward_sp + '\n' +
      'VESTS: ' + reward_vests
      )

if Amount(reward_steem).amount + Amount(reward_sbd).amount + Amount(reward_vests).amount == 0:
    print('\n' + 'No rewards to claim')
    exit()
else:
    client.claim_reward_balance(
        reward_steem, reward_sbd, reward_vests, username)
    print(
        '\n' + 'All reward balances have been claimed. New reward balances are:' + '\n')

userinfo = client.get_account(username)

reward_steem = userinfo['reward_steem_balance']
reward_sbd = userinfo['reward_sbd_balance']
reward_sp = userinfo['reward_vesting_steem']
reward_vests = userinfo['reward_vesting_balance']

print('STEEM: ' + reward_steem + '\n' +
      'SBD: ' + reward_sbd + '\n' +
      'STEEM POWER: ' + reward_sp + '\n' +
      'VESTS: ' + reward_vests
      )

Run it:python auto_claim_bot.py
results meet expectations:
屏幕快照 2020-02-02 下午12.51.53.png

Automatic timing execution on MacOS:$ crontab -e

*/30 * * * * /usr/bin/python /path/auto_claim_bot.py >> /tmp/auto_claim_bot.log
Sort:  

!shop