Live Feed of Posts and Comments - Python3 and beem

in #steem4 years ago

Untitled.jpg
In the last tutorial I provided information how to livestream posts and comments using the original STEEM library for Python. That method still works but the software packages are out of date. An updated STEEM library named beem was created by holger80 to be used with Python3, but its default settings have changed after the contentious fork and community split. The convenient beem package can still be used for the STEEM blockchain by specifying the node and blockchain_instance arguments.

beem is based on the original STEEM library for Python but has unique installation requirements and must be used with updated Python3. Linux users will want to verify the prerequisites are installed:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install curl
sudo apt-get install python3-dev
sudo apt-get install python3-pip
pip3 install -U beem

Save the code below to run in terminal with python3 streamposts.py

streamposts.py
from beem import Steem
steem = Steem(node='https://api.steemit.com')
from beem.blockchain import Blockchain
from beem.comment import Comment
from beem.account import Account
from beem.amount import Amount
chain = Blockchain(blockchain_instance=steem)

while True:
    try:
        for op in chain.stream():
            if op['type'] == 'comment':
                p = Comment(op)
                if p.is_main_post():
                    acc = Account(p['author'], blockchain_instance=steem)
                    print('https://www.steemit.com/@{}/{}'.format(acc.name, p["permlink"]))
    except Exception as error:
        print(error)