Lightsteem 0.0.9 - Introducing event listeners

in #utopian-io6 years ago (edited)


Streaming new operations is a general task we need as app developers, bot developers on the STEEM blockchain. Having helpers for streaming new operations was a priority for the Lightsteem, for a while.

With the new version of Lightsteem, streaming and filtering on the new blocks made easy!

Upgrade to the latest version


(sudo) pip install lightsteem --upgrade

EventListener


Pull Request:
github.com/emre/lightsteem/pull/21

EventListener lives on the lightsteem.helpers.event_listener namespace. It has a couple of params you may pass.

  • client (Lightsteem client instance.)
  • start_block (block number to start streaming. Optional.)
  • end_block (block number to stop streaming. Optional)
Examples:

Stream blockchain for the incoming transfers related to a specific account



from lightsteem.helpers.event_listener import EventListener
from lightsteem.client import Client

client = Client()
events = EventListener(client)

for transfer in events.on('transfer', filter_by={"to": "emrebeyler"}):
    print(transfer)

Stream incoming witness vote actions

events = EventListener(client)

for witness_vote in events.on('account_witness_vote', filter_by={"witness": "emrebeyler"}):
    print(witness_vote)

Stream new comments and posts including utopian-io as a tag

from lightsteem.client import Client
from lightsteem.helpers.event_listener import EventListener

import json

c = Client()
events = EventListener(c)

def filter_tags(comment_body):
    if not comment_body.get("json_metadata"):
        return False

    try:
        tags = json.loads(comment_body["json_metadata"])["tags"]
    except KeyError:
        return False
    return "utopian-io" in tags


for op in events.on("comment", condition=filter_tags):
    print(op)

It's possible and easy to filter every kind of action in the blockchain. If you don't pass start_block or end_block, then the current last irreversible block will be used to start with and listener will stream to the forever.

0.0.8 - Adding Shortcuts for Follow, Unfollow, Ignore, Unignore


Pull Request: github.com/emre/lightsteem/pull/20

With this version, Account helper also gained new methods for Relationship actions.

  • account.follow("username")
  • account.unfollow("username")
  • account.ignore("username")
  • account.unignore("username")

shortcuts added for the convenience. Building custom jsons for these operations were overkill, before.

Notes and the Roadmap


I am switching my old Steem-Python bots/scripts to Lightsteem with the new version. There will be more updates to EventListener, most likely. (API will stay the same but I have a feeling there will be more exception handling and retry mechanisms.)

I don't post micro updates to the blog, so it's better to watch the repo at Github.

Contributing


  • You can stop by Lightsteem discord and join the development with your feedback and ideas.

  • You can pick an open issue and start working on it. But we should reach a consensus about the design decisions before any merge.

  • Make sure you update the documentation and unit tests for each change you do on the codebase.

Sort:  

Thanks for the contribution, @emrebeyler! Will definitely be useful for people that need to stream the blockchain for their bots for example. Personally I only ever used it once, but it was such a hassle with all the crashes that I gave up - do you think yours is/will be more reliable than e.g. the stream function used in steem-python? Also, I was wondering if there is a reason why you don't ever seem to include docstrings (I noticed this in previous contributions as well, I think)?

shortcuts added for the inconvenience

I'm sure you mean convenience ;) - looking forward to more updates, especially the exception handling and retry mechanisms should make it more robust.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Loading...

Thank you for your review, @amosbastian!

So far this week you've reviewed 1 contributions. Keep up the good work!

Hi @emrebeyler!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @emrebeyler!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 62937.86
ETH 3092.40
USDT 1.00
SBD 3.87