用官方的 steem-python 做一个稳健领取 steem 作者奖励和审查奖励的定时机器人

in STEEM CN/中文3 years ago

要求:

  1. 能在各种恶劣网络环境下,正常工作;
  2. 每30分钟定时领取一次
    0.jpg
    由于Steem 官方的 API 节点 https://api.steemit.com 因种种原因而无法访问,其他第三方的API 节点,也出各种状况.所以稳健的机器人,要在这些API 节点动态寻找可用API 节点.

示范程序(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
      )

执行程序:python auto_claim_bot.py
执行结果符合预期:
屏幕快照 2020-02-02 下午12.51.53.png

MacOS 上自动定时执行:$ crontab -e

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

你好鸭,dappcoder!

@lvziyun给您叫了一份外卖!

@jjprac jjprac 在晴空万里 开着巴士 给您送来
蔬菜培根卷

吃饱了吗?跟我猜拳吧! 石头,剪刀,布~

如果您对我的服务满意,请不要吝啬您的点赞~
@onepagex

剪刀


You win!!!! 你赢了!我这新手村猜拳小能手的名号让给你了! 给你1枚SHOP币!

🐂,我也要搞机器人

我所有的梯子都挂了.远程能个机器人,倒是可以省事了
!shop