create account

Query a Hivemind Api with Python by chitty

View this thread on: hive.blogpeakd.comecency.com
· @chitty ·
$72.40
Query a Hivemind Api with Python
Yesterday I was blown away as I read @emrebeyler post about the launch of his new [Hivemind API](https://steemit.com/utopian-io/@emrebeyler/tower-a-rest-api-implementation-on-the-top-of-hivemind).

<center>![Captura de pantalla 2019-01-18 a la(s) 15.55.57.png](https://cdn.steemitimages.com/DQmWWZecb78gy3FQfKEevYKaM1UkhqEmFW563Y7fGJv8CPx/Captura%20de%20pantalla%202019-01-18%20a%20la(s)%2015.55.57.png)</center>

You could of course head over to [tower.emrebeyler.me](https://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](https://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](https://cdn.steemitimages.com/DQmQH8QTX2NsZyhSBtz5b4Hd6tKhRN4Xp1D8arKTM1bmnGh/Captura%20de%20pantalla%202019-01-18%20a%20la(s)%2016.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](https://tower.emrebeyler.me)
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](https://github.com/PixelNoob/python-steem) with some very simple scripts that would allow you to do just that. Feel free to check it out, fork it and contribute.


____

</br>
*Check out my [new witness page](https://witness.chitty.tech) 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
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 78 others
properties (23)
authorchitty
permlinkquery-a-hivemind-api-with-python
categorysteem
json_metadata{"tags":["steem","steemit","api","python","code"],"users":["emrebeyler","provenezuela","elyaque"],"image":["https://cdn.steemitimages.com/DQmWWZecb78gy3FQfKEevYKaM1UkhqEmFW563Y7fGJv8CPx/Captura%20de%20pantalla%202019-01-18%20a%20la(s)%2015.55.57.png","https://cdn.steemitimages.com/DQmQH8QTX2NsZyhSBtz5b4Hd6tKhRN4Xp1D8arKTM1bmnGh/Captura%20de%20pantalla%202019-01-18%20a%20la(s)%2016.05.10.png"],"links":["https://steemit.com/utopian-io/@emrebeyler/tower-a-rest-api-implementation-on-the-top-of-hivemind","https://tower.emrebeyler.me","https://tower.emrebeyler.me/","https://github.com/PixelNoob/python-steem","https://witness.chitty.tech","https://steemconnect.com/sign/account-witness-vote?witness=chitty&amp;approve=1"],"app":"steemit/0.1","format":"markdown"}
created2019-01-18 19:26:33
last_update2019-01-18 19:26:33
depth0
children8
last_payout2019-01-25 19:26:33
cashout_time1969-12-31 23:59:59
total_payout_value55.080 HBD
curator_payout_value17.316 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,817
author_reputation86,901,300,608,582
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id78,581,047
net_rshares123,150,132,500,840
author_curate_reward""
vote details (142)
@arcange ·
Congratulations @chitty!
Your post was mentioned in the [Steem Hit Parade](https://steemit.com/hit-parade/@arcange/daily-hit-parade-20190118) in the following category:

* Pending payout - Ranked 9 with $ 63,95
properties (22)
authorarcange
permlinkre-query-a-hivemind-api-with-python-20190118t173933000z
categorysteem
json_metadata""
created2019-01-19 16:39:51
last_update2019-01-19 16:39:51
depth1
children0
last_payout2019-01-26 16:39:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length211
author_reputation1,146,616,139,479,238
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,621,738
net_rshares0
@ashokcan143 ·
Thanks for sharing...

Posted using [Partiko Android](https://steemit.com/@partiko-android)
👍  
👎  
properties (23)
authorashokcan143
permlinkashokcan143-re-chitty-query-a-hivemind-api-with-python-20190118t220050031z
categorysteem
json_metadata{"app":"partiko","client":"android"}
created2019-01-18 22:00:51
last_update2019-01-18 22:00:51
depth1
children0
last_payout2019-01-25 22:00:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length91
author_reputation19,291,939,570,457
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,586,095
net_rshares22,562,323,041
author_curate_reward""
vote details (2)
@ausbitbank ·
$0.03
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 <a href="http://steemviz.com/aussiesearch ">here</a>, and <a href="https://github.com/ausbitbank/steemviz/blob/master/aussiesearch.js">source code is here</a> :)
👍  ,
properties (23)
authorausbitbank
permlinkre-chitty-query-a-hivemind-api-with-python-20190119t100708620z
categorysteem
json_metadata"{"tags":["steem"],"users":["chitty"],"links":["http://steemviz.com/aussiesearch ","https://github.com/ausbitbank/steemviz/blob/master/aussiesearch.js"],"app":"steemit/0.1"}"
created2019-01-19 10:07:09
last_update2019-01-19 10:07:09
depth1
children1
last_payout2019-01-26 10:07:09
cashout_time1969-12-31 23:59:59
total_payout_value0.021 HBD
curator_payout_value0.006 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length355
author_reputation287,009,709,424,827
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,606,266
net_rshares50,047,948,791
author_curate_reward""
vote details (2)
@chitty ·
Wow! This is really useful and and easy to use! Thanks for sharing it @ausbitbank 

Posted using [Partiko iOS](https://steemit.com/@partiko-ios)
properties (22)
authorchitty
permlinkchitty-re-ausbitbank-re-chitty-query-a-hivemind-api-with-python-20190121t021049293z
categorysteem
json_metadata{"app":"partiko","client":"ios"}
created2019-01-21 02:10:48
last_update2019-01-21 02:10:48
depth2
children0
last_payout2019-01-28 02:10:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length144
author_reputation86,901,300,608,582
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,689,215
net_rshares0
@boomerang ·
This post has received a 41.83 % upvote from @boomerang.
properties (22)
authorboomerang
permlinkre-query-a-hivemind-api-with-python-20190118t213025
categorysteem
json_metadata""
created2019-01-18 21:30:24
last_update2019-01-18 21:30:24
depth1
children0
last_payout2019-01-25 21:30:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length56
author_reputation1,273,205,827,891
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,585,173
net_rshares0
@dailyupvotes ·
$0.05
re-chitty-query-a-hivemind-api-with-python-20190118t224931177z
You got a 83.33% upvote from @dailyupvotes courtesy of @digitalart!

@dailyupvotes is the only bot with guaranteed ROI of at least 1%
👍  
properties (23)
authordailyupvotes
permlinkre-chitty-query-a-hivemind-api-with-python-20190118t224931177z
categorysteem
json_metadata{"app":"postpromoter/2.1.0"}
created2019-01-18 22:49:30
last_update2019-01-18 22:49:30
depth1
children0
last_payout2019-01-25 22:49:30
cashout_time1969-12-31 23:59:59
total_payout_value0.040 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length134
author_reputation746,471,883,194
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,587,333
net_rshares92,772,633,998
author_curate_reward""
vote details (1)
@provenezuela ·
$0.06
Gracias por esta info @chitty ! hemos trabajado dos largos años para alcanzar nuestro nivel de seguidores :)
👍  , ,
properties (23)
authorprovenezuela
permlinkre-chitty-query-a-hivemind-api-with-python-20190118t193509221z
categorysteem
json_metadata{"tags":["steem"],"users":["chitty"],"app":"steemit/0.1"}
created2019-01-18 19:35:09
last_update2019-01-18 19:35:09
depth1
children0
last_payout2019-01-25 19:35:09
cashout_time1969-12-31 23:59:59
total_payout_value0.042 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length108
author_reputation14,629,336,252,341
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,581,339
net_rshares95,398,635,997
author_curate_reward""
vote details (3)
@yol26 ·
Excellent! I'a trying to learn java but is not so easy to star with it.
👍  
properties (23)
authoryol26
permlinkre-chitty-query-a-hivemind-api-with-python-20190118t210617712z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2019-01-18 21:06:18
last_update2019-01-18 21:06:18
depth1
children0
last_payout2019-01-25 21:06:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length71
author_reputation334,121,873,056
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id78,584,488
net_rshares33,050,874,343
author_curate_reward""
vote details (1)