Skip to content

Instantly share code, notes, and snippets.

@TheCrazyGM
Created April 11, 2020 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheCrazyGM/9b2882a4adcea826815489b5a00ed089 to your computer and use it in GitHub Desktop.
Save TheCrazyGM/9b2882a4adcea826815489b5a00ed089 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import dataset
from beem import Steem
from beem.blockchain import Blockchain
watch = "thecrazygm"
hive = Steem(node='https://anyx.io')
db = dataset.connect('sqlite:///mydatabase.db')
# System Variables
blockchain = Blockchain(steem_instance=hive)
stream = blockchain.stream(opNames=['transfer'], raw_ops=False, threading=True, thread_num=4)
table = db[watch]
# parse json data to SQL insert
def update_db(post):
try:
table.insert(dict(post))
db.commit()
except Exception as e:
print(f'[Error: {e} moving on]')
db.rollback()
def monitor():
print("[Starting up...]")
db.begin()
# Read the live stream and filter out only transfers
for post in stream:
if post["to"] == watch or post["from"] == watch:
print(f"[Transaction Found from {post['from']} to {post['to']}]")
update_db(post)
if __name__ == "__main__":
monitor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment