Started Playing With BEEM Library

1.png
source

I've been always interested in Blockchain technologies and how they work. But the same time, "Blockchain", the word, kind of intimidated me so I never actually played with it before.

Then I saw this post few weeks ago,

Splinterlands Move - STEEM blockchain BEFORE/AFTER @danielsaori

I was very surprised when I saw the script...
I thought blockchain stuff was like this complicated, mind bending special kind of technology. (i still think some stuff, a lot of stuff are super complex...)
WjRDn37.gif
source

But the script was pretty easy and very straightforward so I was like WTH 🤯 maybe I can do something with it!
I started reading documentations and did some tutorials.
https://beem.readthedocs.io/en/latest/tutorials.html

Tutorials are like this 👇 small simple program to get account history
3.png
source

But when I copy and paste it, I got an error and it didn't run so I tried other tutorials.
I think some stuff worked as it but other tutorials gave an error and complained about something so I had to play around with them more.
Maybe these tutorials are meant to be more like exercises.

But anyway, I was able to make a script that displays my last 30 days curation + author rewards.
2.png

Honestly the graph is ugly and I don't like it. I wanted to make it pretty but this was not about the graph, playing with blockchain and getting some data out it was pretty cool.

This is my script.

from datetime import datetime, timedelta
from beem import Steem
from beem.account import Account
from beem.amount import Amount
from matplotlib import pyplot as plt
import seaborn as sns

steem = Steem()
account = Account("tomoyan")

def calc_rewards(start, stop):
print('START:', start, 'STOP:', stop)
curation_reward_vests = Amount('0 VESTS')
author_reward_vests = Amount('0 VESTS')

curation_rewards_hp = 0.0
author_rewards_hp = 0.0

operations_list = ['curation_reward', 'author_reward']

rewards = account.history_reverse(
    start=start,
    stop=stop,
    only_ops=operations_list)

for reward in rewards:
    if reward['type'] == 'curation_reward':
        if Amount(reward['reward']):
            curation_reward_vests += Amount(reward['reward'])
    elif reward['type'] == 'author_reward':
        if Amount(reward['vesting_payout']):
            author_reward_vests += Amount(reward['vesting_payout'])

curation_rewards_hp = steem.vests_to_sp(curation_reward_vests.amount)
author_rewards_hp = steem.vests_to_sp(author_reward_vests.amount)

print(f"CURATION_REWARD: {curation_rewards_hp:.4}")
print(f"AUTHOR_REWARDS_HP: {author_rewards_hp:.4}")

return {
    'curation_reward': f"{curation_rewards_hp:.4}",
    'author_reward': f"{author_rewards_hp:.4}",
}

def plot_data(months, curation_hp, author_hp):
sns.set()
plt.plot(months, curation_hp, label='Curation HP', marker='o')
plt.plot(months, author_hp, label='Author HP', marker='o')
plt.legend()
plt.show()

counter = 0
duration = 30 # 30 days
months = []
curation_hp = []
author_hp = []

for i in range(duration):
start = datetime.utcnow() - timedelta(days=counter)
stop = datetime.utcnow() - timedelta(days=counter + 1)

rewards_data = calc_rewards(start, stop)
months.insert(0, start.strftime('%Y/%m/%d'))
curation_hp.insert(0, float(rewards_data['curation_reward']))
author_hp.insert(0, float(rewards_data['author_reward']))

counter += 1

plot_data(months, curation_hp, author_hp)

Obviously, I don't know how to paste the code here 😩... but anyway, I did it!
I am going to play around with it more and try making something more meaningful :)


Get Rewarded For Browsing! Are you Brave?


Posted with Esteem
t.png

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now