My SprayBot - Part 1: Daily automated transfer to @whalefountain

in #steemwhale6 years ago (edited)

Hi Steemians,


Image source: https://pixabay.com/de/roboter-computer-bots-charakter-764951/

welcome to my little series about my new SprayBot for the https://steemwhale.io/ fountain.

I try to spend a spray every day, which takes me some minutes to

  • send the STEEM or SBD to @whalefountain
  • wait for the spray and the response from @whalefountain, which contains an image url
  • posting the image

Since I am a lazy person, I have now automated these steps.

In the first part of this tutorial I want to show how to trigger an automated transfer to @whalefountain.

For interaction with the STEEM blockchain I'm using the awesome Beem library (https://beem.readthedocs.io/en/latest/index.html) from @holger80 on Ubuntu. After the installation of beem we can start coding.

If we want to send a transfer, we need some import-statements first.

from beem.steem import Steem
from beem.account import Account
from beem.instance import set_shared_steem_instance

With this statements we create a Steem-Client, which is connected to the API Endpoint of Steemit.

active_wif = "FILL_IN_PRIVATE_ACTIVE_KEY_HERE"

stm = Steem(
    node = "https://api.steemit.com/",
    bundle=True, 
    keys=[active_wif]
)

set_shared_steem_instance(stm)

Since the memo of the transfer is shown on steemwhale.io, I need to add the current date to the memo.

I need to import datetime and one line of code is sufficient to generate the memo.

import datetime

memos = datetime.date.today().strftime("Let's spray (%Y-%m-%d)")

Now we can send the transfer. First an instance of Account is needed. After the call of the transfer-method the transfer is broadcasted to the STEEM blockchain

account = Account("YOUR_ACCOUNT_NAME")
account.transfer("whalefountain", 1, "STEEM", memo = memos)
stm.broadcast()

Finally I want this transfer to run automatically at the same time every day. Therefore I will use a so called "cronjob", which starts a shell script. The shell script is very tiny ...

#!/bin/bash
nohup python3 dailyspray.py >> dailyspray.log &

The transfer shall happen every day 8 AM UTC. Therefore this config in crontab is sufficient ...

~/steem/dailyspray$ crontab -l
0 8 * * * dailyspray.sh

In part 2 I will show how to read Blockchain events using beem. Stay tuned:

https://steemit.com/steemwhale/@tufkat/my-spraybot-part-2-reading-the-blockchain-stream-and-filtering-transfers

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63643.10
ETH 2582.85
USDT 1.00
SBD 2.75