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...)
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
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.
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)
Anyway, I did it! My first beem script.
I am going to play around with it more and try making something more meaningful :)
Get Rewarded For Browsing! Are you Brave?
@tomoyan first of all very informative article. Wow at least you are learning new things that is quite exciting.
I tried to get you connected but I cannot found you on discord. If possible can you please provide your id.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you thank you!
Can you find me @tomoyan on PH discord channel?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wow! What a very lovely script you have over there. I'm currently learning how to write codes with python programming language and I am still at a novice level. I'll surely try out my own script using python programming language after learning the important basics.
Thanks for sharing this great post with love from @hardaeborla and I hope you have a great day ahead
💖💕❤️💖❤️💖💖❤️💖❤️💖❤️💖❤️💖💕❤️💖
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
hahaha its nothing special. i was just playing around with it
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit