My Progress to Orca in Python (using JupyterLab)

It has been a while!

Since my last post... I have been lacking the necessary time and disposition to share some interesting stuff. To add on that, life has not been easy lately, so, yep... I was just enjoying watching things around. Mostly playing #HIVEGames and watching the progress of the HIVE dev activity.

Disclaimer: this is a really basic example, but just felt like a good simple one on how to show everyone an easy way to play with the HIVE API.

Note: This was driven from Windows (using JupyterLab from Anaconda) but you can do the same from any Linux machine. The idea was to show how that in the Windows platform you can do the same experiments.

The main part of the code

This includes the url to the API node you are requesting the information. Change that to another one if that's your intention. Then, there is some encoding format of the message being sent, and finaly the API call documented here. Lastly, you send the request, by post method.

import requests
import json from requests.structures import CaseInsensitiveDict

#url = "https://rpc.esteem.app"
url = "https://api.hive.blog"

headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"

# API request for the get_accounts function for the  in "params":[[""]]
data = '{"jsonrpc":"2.0", "method":"condenser_api.get_accounts", "params":[["forykw"]], "id":1}'

# Sending the API request
resp = requests.post(url, headers=headers, data=data)

This output is just to understand how the communication goes

# Print the status and reason of the request
print("Status Code:",resp.status_code,"Reason:",resp.reason)

# Print how long took for the request to be received
print("Request time:",resp.elapsed)

In this case all was good (quite fast response too)

Status Code: 200 Reason: OK
Request time: 0:00:01.054829

I usually get under the 1 second of response time. This one was one of the worst ones.

If you need to see all the output you are getting

Uncomment this line and you will get the entire response in JSON format.

# If you need to see the detailed output of the request in JSON format, uncomment this
#json.loads(resp.text)

Then the actual requests

I have added a couple more things just to exemplify how can you get other things form the JSON output.

# Save the request output into a variable
json_data = json.loads(resp.text)

# Print the account HIVE Balance
print("HIVE Balance:",json_data['result'][0]['balance'])

# Print the account Voting Power in %
print("Voting Power:","{:.2%}".format(json_data['result'][0]['voting_power'] / 10000))

# Print the account progress in % to Orca status (100 Million VESTS)
print("Progress to Orca:","{:.12%}".format(float(json_data['result'][0]['vesting_shares'].split()[0]) / 100000000))

The result 🙃😎

HIVE Balance: 41.460 HIVE
Voting Power: 91.44%
Progress to Orca: 63.878949907716%

#HIVEGames

This hashtag is valid both on Hive and Twitter. So, if you have an account on either and you are up to post about dCity, make sure you use both #dCity and #HIVEGames. If you wish, also tag me on Twitter, the account I use there is mentioned bellow.

(credit @doze)

Supporting this initiative will be a tremendous help to the #HIVE ecosystem, especially if your area is into the #Blockchain #Games world. For more details of how this started, check the side image that links to the post.

Any questions, advice requests or comments are welcome, either here or anywhere else you find me.

🖐️HIVE5's!

Have fun, good luck on all the gaming and lots of teaching "how to play" to new players.

Do you know about my new Twitter account?

If you have an account on Twitter (follow @forkyishere) and you enjoy #news about the #HIVE blockchain, make sure you tweet about any reference to your account here. I am following all HIVE users!


Check these Cryptocurrency 💳Cards

Crypto.comCrypteriumTenXRevolutWirex

by @forykw

H2
H3
H4
3 columns
2 columns
1 column
9 Comments
Ecency