Steemit 自动收取收益折腾小记

in #cn7 years ago (edited)

昨天看到 O 哥( @oflyhigh )的教程——How to claim your rewards automatically? / 如何自动收取你的收益,看着挺简单的,其实也不难。

euro-447214_640.jpg

Source

于是,拿手上便宜的搬瓦工试着折腾,Reload 几次都没折腾出来。主要是因为搬瓦工上安装有一个 Python 2.x 版本的爱国小工具,而 steem-python 需要 Python 3.5 以上。

折腾几遍,搞不定 Python2.x 与 Python 3.6.2 共存。Python2.x 与 Python 3.6.2 都安装成功,默认 Python 是 Python 2.x,按网上教程将 Python3 软链到 Python 3.6.1,运行 Python3 -V 出来的版本确实也是 3.6.1。pip3 install -U steem 也能顺利安装成功。

可是,运行 steempy --version 检查一下有没安装成功,SSH 几次都是老老实实返回:steempy:command not found。后来连爱国小工具也不能正常工作。

实在是被自己打败,只好退而求其次,爱国小工具换成 libev 版本,系统默认用 Python 3.6.1。

Python & steem-python 环境安装


Python 3.6.1 是使用 steem-python documentation 推荐的 Anaconda 安装。

附上简单安装方法:

wget https://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh

chmod +x Anaconda3-4.4.0-Linux-x86_64.sh

~/Anaconda3-4.4.0-Linux-x86_64.sh

一直按回车,直到看到 Do you approve the license terms? [yes|no] 字样,输入 yes 回车。

接着会提示安装路径,默认安装到 /root/anaconda3,如果不需要更改安装路径,直接按回车就好。

安装结束,会提示是否把 Anaconda3 安装路径添加到系统 /root/.bashrc 的 PATH。不想麻烦的话输入 yes 回车就好。

installation finished.

Do you wish the installer to prepend the Anaconda3 install location to PATH in your /root/.bashrc ? [yes|no]

如果不小心按错了,也可以手工把下面的添加到 /root/.bashrc 文件。

export PATH=/root/anaconda3/bin:$PATH

重启一下 VPS,python -V 可以验证 Python 3.6.1 是否安装成功。如无意外,会返回信息:Python 3.6.1 :: Anaconda 4.4.0 (64-bit)。

接下来敲入 pip install steem 应该就能愉快的把 steem-python 安装上。

运行 steempy --version 就能看到 steempy 版本信息,如:steempy 0.18.93

自动收取收益 Python 代码


来自 @yuxi,vi 新建名称为:claim_rewards_for_zhijun.py 的文件,贴入下面代码保存退出。

#!/root/anaconda3/bin/python
from steem import Steem
from steem.account import Account

user = '这里输入你的 Steemit ID'
account = Account(user)

wif = {
    "posting": "这里是 posting key"
}

try:
  steem = Steem(keys=wif)

  sbd   = account.balances["rewards"]["SBD"]
  st      = account.balances["rewards"]["STEEM"]
  vests = account.balances["rewards"]["VESTS"]

  if sbd >0 or st >0 or vests > 0:
    print('claiming rewards ... ')
    steem.claim_reward_balance(account=user)

  else:
    print('nothing to claim')

except:
  print('oops, something not right.')

使用 crontab 定时运行 claim_rewards_for_zhijun.py 脚本收取收益


crontab -e

* */1 * * * /root/claim_rewards_for_zhijun.py >>log.txt 2>&1

每小时收取一次。

注意


最好运行 service crond status 检查 crond 服务是否启动,service crond start 可手动启动,或者设置开机启动:chkconfig --level 35 crond on

Centos 7 x86_64 实测通过

参考文章:

@oflyhighHow to claim your rewards automatically? / 如何自动收取你的收益

@yuxiPython Steem API介绍系列#4 - 转账操作篇

竹子-博客:每天一个linux命令(50):crontab命令

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64344.02
ETH 3142.36
USDT 1.00
SBD 4.01