Query a Hivemind Api with Python by chitty

View this thread on steempeak.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)
post_id68,995,867
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
net_rshares123,150,132,500,840
last_payout2019-01-25 19:26:33
cashout_time1969-12-31 23:59:59
total_payout_value55.080 SBD
curator_payout_value17.316 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3,817
author_reputation84,463,031,858,396
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
author_curate_reward""
vote details (142)
@provenezuela ·
$0.06
Gracias por esta info @chitty ! hemos trabajado dos largos años para alcanzar nuestro nivel de seguidores :)
👍  , ,
properties (23)
post_id68,996,130
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
net_rshares95,398,635,997
last_payout2019-01-25 19:35:09
cashout_time1969-12-31 23:59:59
total_payout_value0.042 SBD
curator_payout_value0.013 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length108
author_reputation14,603,079,328,664
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
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)
post_id68,998,985
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
net_rshares33,050,874,343
last_payout2019-01-25 21:06:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length71
author_reputation704,332,579,924
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@boomerang ·
This post has received a 41.83 % upvote from @boomerang.
properties (22)
post_id68,999,609
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
net_rshares0
last_payout2019-01-25 21:30:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length56
author_reputation3,503,034,741,265
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@ashokcan143 ·
Thanks for sharing...

Posted using [Partiko Android](https://steemit.com/@partiko-android)
👍  
👎  
properties (23)
post_id69,000,419
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
net_rshares22,562,323,041
last_payout2019-01-25 22:00:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length91
author_reputation3,696,389,924,413
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@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)
post_id69,001,523
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
net_rshares92,772,633,998
last_payout2019-01-25 22:49:30
cashout_time1969-12-31 23:59:59
total_payout_value0.040 SBD
curator_payout_value0.013 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length134
author_reputation747,021,898,927
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@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)
post_id69,018,546
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
net_rshares50,047,948,791
last_payout2019-01-26 10:07:09
cashout_time1969-12-31 23:59:59
total_payout_value0.021 SBD
curator_payout_value0.006 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length355
author_reputation225,597,006,884,358
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
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)
post_id69,093,352
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
net_rshares0
last_payout2019-01-28 02:10:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length144
author_reputation84,463,031,858,396
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@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)
post_id69,032,519
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
net_rshares0
last_payout2019-01-26 16:39:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length211
author_reputation231,443,210,169,699
root_title"Query a Hivemind Api with Python"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000