My SprayBot - Part 2: Reading the Blockchain Stream and filtering transfers
Hi Steemians,
Image source: https://pixabay.com/de/roboter-computer-bots-charakter-764951/
welcome to part 2 of little series about my new SprayBot for the https://steemwhale.io/ fountain.
In part 1 we learned how to send a transfer automatically to another STEEM account.
After the successful transfer we have to listen to the STEEM blockchain to detect the incoming transfer from @whalefountain with the image URL.
We need an instance of Blockchain, which is configured with a STEEM client (Instance of Steem).
In a while-loop we stream all Blockchain events until we find a transfer from @whalefountain to our account.
from beem.blockchain import Blockchain
...
stm = Steem(node = "https://api.steemit.com/", bundle=True, keys=[active_wif])
chain = Blockchain(steem_instance = stm)
while True:
try:
for operation in chain.stream(only_ops=False):
if operation["type"] == "transfer":
if operation["from"] == "whalefountain":
if operation["to"] == "YOUR_ACCOUNT_NAME":
imgUrl = extractUrl(operation["memo"])
The extraction of the image url is also very easy.
Sometimes one get's two transfers from @whalefountain, that's why I check if the memo ends with "gif".
def extractUrl(memo):
if (memo.endswith("gif")):
imgUrl = memo[memo.index("https://i.imgur.com"):]
return imgUrl
return None
In the 3rd and final part I will show you how to create a post with beem.
Good informative article on SprayBot.
well done my dear friend.
Interesting tufkat I will check out your part 3. I do enjoy how you pull the sm db. Is it possible you can point me in a direction for my own personal learning on creating data tables and how you present such public data from the blockchain. Any open source stuf of your own or should I try utopian?
Posted using Partiko Android