Python Beem + Blurt: Upvote Count
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?


➡️ Website