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.