Python Beem + Blurt: Upvote Count

in #python3 months ago


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... 🤯🤯🤯


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

def main():
    vote_data = {}

    # setup blurt nodes and account
    blurt_nodes = ['', '']
    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:
            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']}
                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:

if __name__ == '__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