Query a Hivemind Api with Python

in #steem5 years ago

Yesterday I was blown away as I read @emrebeyler post about the launch of his new Hivemind API.

Captura de pantalla 2019-01-18 a la(s) 15.55.57.png

You could of course head over to tower.emrebeyler.me and play with the very simple to use Graphic Interface that @emrebeyler has built for us, but if you want to do some development I found that the simplest way for me was to query his API to fetch a result, then you could turn that result into a variable and do all sort of things with it.

In this guide I will provide two examples of how we could get:

1.- The number 1 account in Venezuela sorted by Followers.

2.- The account in Venezuela with the most reputation.

We all know Venezuela is pretty big in Steemit, but lets find out who is the king!

Fetch account by Location and Followers

To know what URL you should use for your query, you can go to tower.emrebeyler.me, pick the filters that you wish to look for and then paste the output after the https://tower.emrebeyler.me/ domain :

Captura de pantalla 2019-01-18 a la(s) 16.05.10.png

So the url you want to use is: https://tower.emrebeyler.me/api/v1/accounts/?limit=1&location__contains=Venezuela&ordering=-followers
The minus sign (-) before "followers" specifies that we want the result ordered by the account with most followers first.

So, our python3 script would look something like this:

from urllib.request import urlopen
import json

url = urlopen('https://tower.emrebeyler.me/api/v1/accounts/?limit=10&location__contains=enezuela&ordering=-followers').read()
result = json.loads(url)

one = result['results'][0]["name"]

fone = result['results'][0]["followers"]

print (one, fone)

What we are doing is basically querying the .json output that can be very long and hard to understand into a simple python script that would give us the account with most followers in Venezuela, this is the result:

provenezuela 6094

So with more that 6k followers we now know that @provenezuela is the king of Steemit followers in Venezuela, but how about the account with most rep? - well I was excited to see the result of this since its an old friend of mine in Steemit :)

We will use the exact same code but we will only change the "followers" parameter and change it for "reputation":

from urllib.request import urlopen
import json

url = urlopen('https://tower.emrebeyler.me/api/v1/accounts/?limit=10&location__contains=enezuela&ordering=-reputation').read()
result = json.loads(url)

one = result['results'][0]["name"]

fone = result['results'][0]["reputation"]

print (one, fone)

And the outcome is...

elyaque 70.34

My man @elyaque who is an old-timer in Steemit has an amazing 70.34 rep!

So, with a little bit of magic and a bit more code, you could use this outputs to follow certain accounts, send a message to them or vote for their latest post. I have created a personal Python-Steem repository on GitHub with some very simple scripts that would allow you to do just that. Feel free to check it out, fork it and contribute.



Check out my new witness page to find out what I am doing for Steem and support my work voting for my witness:

https://steemconnect.com/sign/account-witness-vote?witness=chitty&approve=1

Sort:  

Gracias por esta info @chitty ! hemos trabajado dos largos años para alcanzar nuestro nivel de seguidores :)

You got a 83.33% upvote from @dailyupvotes courtesy of @digitalart!

@dailyupvotes is the only bot with guaranteed ROI of at least 1%

Great python tutorial @chitty !

I recently made a javascript tool using this same tower/hivemind api for searching users by location that your readers may be interested in.

It's available at here, and source code is here :)

Wow! This is really useful and and easy to use! Thanks for sharing it @ausbitbank

Posted using Partiko iOS

Excellent! I'a trying to learn java but is not so easy to star with it.

This post has received a 41.83 % upvote from @boomerang.

Congratulations @chitty!
Your post was mentioned in the Steem Hit Parade in the following category:

  • Pending payout - Ranked 9 with $ 63,95