Python Beem + Blurt: Upvote Count

avatar

2.png

I made this simple script to find out who have upvoted me and how many times in the last 7 days.
The result was surprising... 🤯🤯🤯

Script: vote_count.py

from beem import Blurt
from beem.account import Account
from datetime import datetime, timedelta
from pprint import pprint

# who's upvote data you like to see?!
USERNAME = 'tomoyan'

# last 7 days
DURATION = 7


def main():
    vote_data = {}

    # setup blurt nodes and account
    blurt_nodes = ['https://rpc.blurt.buzz', 'https://blurtd.privex.io']
    blurt = Blurt(blurt_nodes)
    blurt_account = Account(USERNAME, blockchain_instance=blurt)

    stop = datetime.utcnow() - timedelta(days=DURATION)

    # get user's upvote history and store counts and weights
    for op in blurt_account.history_reverse(stop=stop, only_ops=['vote']):
        if op['voter'] == USERNAME:
            continue
        else:
            if op['voter'] in vote_data:
                vote_data[op['voter']] = {
                    'count': vote_data[op['voter']]['count'] + 1,
                    'weight': vote_data[op['voter']]['weight'] + op['weight']}
            else:
                vote_data[op['voter']] = {'count': 1, 'weight': op['weight']}

    # calculate vote weight average
    for vote in vote_data:
        vote_data[vote]['weight'] = vote_data[vote]['weight'] / \
            vote_data[vote]['count'] / 100
        vote_data[vote]['weight'] = f'{vote_data[vote]["weight"]:.2f}'

    # sort vote data by counts in descending order
    vote_data = sorted(vote_data.items(),
                       key=lambda x: x[1]['count'], reverse=True)

    # print the result
    for vote in vote_data:
        pprint(vote)


if __name__ == '__main__':
    main()

I think I am going to make a chart out of it when I have time. This would be a nice feature for my tool... 🤔


Get Rewarded For Browsing! Are you Brave?

happy tears
➡️ Website
➡️ Twitter



0
0
0.000
1 comments
avatar

Congratulations @tomoyan! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You distributed more than 6000 upvotes. Your next target is to reach 7000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @hivebuzz:

Feedback from the November 1st Hive Power Up Day
0
0
0.000