Automating checking for active users with Python

Last week I put out a post listing Hive users in the UK who are active. This was based on a list compiled by @pennsif, but he himself is inactive lately. Checking for activity was a fair bit of work and I realised it should be possible to automate it.

I posted before about using the beem to query the Hive blockchain. I was able to use some of the same functions for this.

This is from the original post. The new format will be slightly different.

Actually finding UK users is still a manual task as there is there is no one thing to search for in the profile location and many people do not fill it in anyway. I had lots of suggestions after I posted the list. I am now adding them to a text file that looks like this:

R, London & the South East
U, adetorrent
U, andy4475
U, atomcollector
U, basilmarples
U, bleepcoin
U, chris-uk
U, cryptogee

I break it up into regions that start with R and users (U). I am tempted to simplify that. I did a bit of find and replace on the text of my post to generate the file without having to re-type too much. They are mostly alphabetical in the file, but I am sorting the results anyway.

I am saying someone is active if they posted or voted in the last month. Lots of people are just using automatic votes and not actually posting. My script splits out those who just vote and lists as inactive those who at least used Hive since it started.

This is the bit that checks for activity. There are loads of different 'ops' you can check for. I went for those that I thought mattered most for this. I just noticed that the 'comment' op is also used if a post or comment is edited, but I will take that as a sign of activity.

def useractive(user):
    # Work back looking for last post/comment or vote
    acc = Account(user)#, blockchain_instance=hive)
    voted = commented = False

    for a in acc.history_reverse(stop=stop, only_ops=["vote", 
                                                      "comment"]):
        if a["type"] == "vote":
            voted = True
        if a["author"] == user:
            if a["type"] == "comment":
                commented = True
                break # Don't need to check if they voted as well
            
    return (voted, commented)

The rest of the code is just about looping through the users and compiling the lists which are then output in a readable form. You can find all the code in my GitHub. I am using Jupyter Notebook again as it makes for simple experimentation. Scanning over a hundred users takes about three minutes, which is not too bad as I will probably only do this about once per month.

I am still on the lookout for other Brits on Hive to add to the list, so let me know of any you encounter. If you want help adapting this for your own country let me know. It may get unwieldy for many hundreds of people, but that may be a way off in the UK at least.

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