scrypt to get last STEEM blockchain active users

in #steem7 years ago (edited)

Hello folks,

I've written a very simple python script, it needs STEEM PYTHON API installed.

Capture_.PNG

The script is an infinite loop that extract all the last hour active users on the STEEM blockchain, and adds them into a file. Every hour it keeps adding users that are not on the file already, and that have done some activity recorded in the blockchain.

The script is very simple, and not "elegant" at all, but I wrote it in 20 minutes, so please be patient about this, I'll try to update it, and get it a bit more "elegant" when I'll get some time, for now it does it job with no issue ;)

here it is:

from steem import Steem

from steem.blockchain import Blockchain

import time

import re


b=Blockchain()

s=Steem()


def hour_active():

    bl_num=int(b.get_current_block_num())

    bl_num_=bl_num-1250

    bl=(str(s.get_blocks_range(bl_num_,bl_num)))


    x=('follower','account','voter','from','author')

    account=[]

    for i in x:

        acc=re.findall('"'+i+'":"(.+?)"',str(bl))

        for l in acc:

            if l not in account:

                account.append(l)

        

    file=open('active_acc.txt','r')

    old=file.readlines()

    file.close()

    file=open('active_acc.txt','a')



    for i in account:

        if i+'\n' not in old:

            file.write(str(i)+'\n')

    file.close()

    print ('one hour accounts',len(account))

    print ('total accounts',len(old))


counter=1

while True:

    print (counter)

    try:

        hour_active()

    except Exception :

        pass

        print ('FAILED')

    counter+=1

    print ('__________________________')

    time.sleep(3600)

here my repository on GitHub if you prefer to check it there:

https://github.com/digital-mine/get_steem_active_users

That's all folks

please upvote and follow ;)

Sort:  

Just updated the script!

I added a couple of lines to being able to keep track of the last our BRAND NEW users ;)

Thanks for the example code, @digital.mine. Having difficulties reaching api.steemit.com at the moment yet doubt that is your script's problem. Will let things cool down on the blockchain for a couple of days and explore further at that time.

Is there a link that you know of explaining all the available calls in the python api or need one check the source for that?

There is the wiki that explains all the possible calls. Now I'm outside later I'll give you the link

Let me know if you need something else, always a pleasure when I can help

Hi @digital.mine,
Greate job! I will be aware of the development of this script.
Do you intend to develop anything else with the information that you extract into file?

Thx!

Yes I will and I'll post here as well as on github ;)

Coin Marketplace

STEEM 0.16
TRX 0.17
JST 0.028
BTC 69086.63
ETH 2471.20
USDT 1.00
SBD 2.39