create account

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

View this thread on: hive.blogpeakd.comecency.com
· @tufkat · (edited)
$2.48
My SprayBot - Part 1: Daily automated transfer to @whalefountain
# Hi Steemians,
####

https://cdn.steemitimages.com/DQmSJsA6GpFYbF1DPtFBRrKwR6vf7w6RFyfKnZtLc3Rr4Qj/robots-764951_1280.png
<i>Image source: https://pixabay.com/de/roboter-computer-bots-charakter-764951/</i>


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 

https://steemitimages.com/0x0/https://i.imgur.com/6MrZ8kt.gif

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.

https://cdn.steemitimages.com/DQmSjWe4obv5jEotHvCazupE3f9Hj5AQoE4AjSPzatuaPwm/Supporters.png

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
👍  , , , , , , , , , , , , , , , ,
properties (23)
authortufkat
permlinkmy-spraybot-part-1-daily-automated-transfer-to-whalefountain
categorysteemwhale
json_metadata{"tags":["steemwhale","beem","python","steem-dev","utopian-io"],"users":["whalefountain","holger80"],"image":["https://cdn.steemitimages.com/DQmSJsA6GpFYbF1DPtFBRrKwR6vf7w6RFyfKnZtLc3Rr4Qj/robots-764951_1280.png","https://steemitimages.com/0x0/https://i.imgur.com/6MrZ8kt.gif","https://cdn.steemitimages.com/DQmSjWe4obv5jEotHvCazupE3f9Hj5AQoE4AjSPzatuaPwm/Supporters.png"],"links":["https://pixabay.com/de/roboter-computer-bots-charakter-764951/","https://steemwhale.io/","https://beem.readthedocs.io/en/latest/index.html","https://steemit.com/steemwhale/@tufkat/my-spraybot-part-2-reading-the-blockchain-stream-and-filtering-transfers"],"app":"steemit/0.1","format":"markdown"}
created2018-09-11 12:06:57
last_update2018-09-11 13:40:42
depth0
children0
last_payout2018-09-18 12:06:57
cashout_time1969-12-31 23:59:59
total_payout_value1.880 HBD
curator_payout_value0.600 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,723
author_reputation50,754,527,204,325
root_title"My SprayBot - Part 1: Daily automated transfer to @whalefountain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id70,979,355
net_rshares2,413,129,740,353
author_curate_reward""
vote details (17)