Playing with beem to query Hive

avatar

I have been looking out for some personal programming projects and doing something with Hive was appealing. Luckily others have already done the hard work of providing libraries to do this. One of these is beem for Python by @holger80.

I will not leap straight into creating transactions yet, but I can do some simple queries. There is documentation for the library and it is a matter of finding the appropriate functions. There are some code examples.

Initially I am trying to replicate some of what Hive Now does. I am using Jupyter Notebook which makes it easy to experiment with small blocks of code. I have put the full notebook on Github in case it is useful to anyone, but this is part of what it does. Notebook makes the links clickable.

Code

You have to install the beem library. I am using Ubuntu Linux, but it should work on other operating systems too. I had to install a few other libraries it depends on. I used this to install beem itself:

pip3 install -U beem

When I tried to import the library in Python itself it did not find it. This fixed it. I am using Python 3.7.4. pip3 seems to be using Python 3.8, so maybe it put things in the wrong location.

python -m pip install beem

Making a connection to Hive is pretty simple. Once you have imported the libraries you just do something like this. beem works with Steem too, so you have to tell it to use Hive instead and there are a couple of ways to do this. The commented parameter on the Account call could be used instead of set_shared_blockchain_instance(hive):

hive = Hive()
user ='steevc'
max_lines = 10
set_shared_blockchain_instance(hive)
acc = Account(user)#, blockchain_instance=hive)

You then have access to your full history of transactions as you would see on Hiveblocks. It is a matter of pulling out appropriate values. Rewards are expressed in VESTS and so need conversion. To get HP for curation I used acc.blockchain.vests_to_hp. Working out the value of a vote may be more complex as I think you would need to look at the HP of the voter. It would be an estimate anyway.

I will look into other functionality. I can customise what this query does to suit my needs. It might be fun with write some sort of bot, but I will probably not use my main account for that and will be careful to not spam the system. Key management is required for that and I will have to make sure I do not expose them in any public code. If I do code a bot then I might want it to run on a Raspberry Pi so I do not need to leave the PC on all the time. I have an LED display for a Pi that could show status messages. I did some of that ages ago.

I am open to other suggestions for things to try.

Happy hacking!



0
0
0.000
10 comments
avatar
(Edited)

.

0
0
0.000
avatar

I'll have a play on a Pi soon. Thanks for the tips.

!ENGAGE 20

0
0
0.000
avatar

Thank you for your engagement on this post, you have recieved ENGAGE tokens.

0
0
0.000
avatar

I've got to start playing with this again soon. Thanks for posting.

0
0
0.000
avatar

It would be great to see more people getting into it and coming up with cool apps. Maybe we need some sort of contest to bring in more of the open source community. Hive ought to be a natural home for them.

0
0
0.000
avatar

I love that so many of these Blockchain projects are open source where you can write your own code to interact with them. I wish I had kept up to date with my coding skills. I was horrible at it, but it was a nice tool to have under your bed. I think my biggest issue with coding in college was none of the projects seemed personal. I needed something more tangible that I could actually see myself using in everyday life so I could connect with it.

0
0
0.000
avatar

I need to find projects that engage me. I need to play around with this to see what I can do. I can use a different account if I want to actually do transactions.

0
0
0.000
avatar

Nice, beem is a really useful tool to have at your disposal, and is how I interact with Hive for anything technical, I've got a python script written in Beem running as we speak, and it works like a charm. Nice to see you getting into it.

Best of luck on your adventure & thanks for posting to programming!

0
0
0.000
avatar

It looks like some stuff is fairly simple to do. What does your script do?

0
0
0.000