Steem for Script Kiddies: SteemFollowerStats.py - A program by ChatGPT

in #steemtalklast month (edited)

Hobby programming time has been preempted by actual work for the last two weeks, so there's not much point in writing a programming diary entry today. I have basically done almost nothing. (There. Diary entry done. 😎)

However, this morning I was able to spend a little bit of time working towards incorporating the strength of the follower network into my autovoter. In order to do this, I started with Google Bard Gemini, but Gemini failed in just three prompts, so I switched over to ChatGPT, instead. ChatGPT produced a decent result, so I thought I'd share it here for future reference by others.

The goal for this morning was to slap together a program that parses the output from the Steem condenser_api/get_followers call for a particular author and returns the follower count and the median reputation of the author's followers.

The idea here is that (along with author reputation), these values can give the autovoter some insight into the value that people place on this author's content. Authors with "stronger" follower networks will receive larger votes. It seems to me that (with a sufficiently high follower count), the median follower reputation metric is especially difficult for an author to game.

In order to accomplish this, I started by prompting ChatGPT to write a python program that would give me the desired information. Here's what the AI came up with:

#!/usr/bin/python3

import sys
import json
import requests
import statistics

def get_followers(account):
    followers = []
    start_account = None

    while True:
        # Define JSON-RPC request payload
        payload = {
            "jsonrpc": "2.0",
            "method": "condenser_api.get_followers",
            "params": [account, start_account, "blog", 1000],
            "id": 1
        }

        # Make POST request to Steem API
        response = requests.post('https://api.steemit.com', json=payload)

        # Parse JSON response
        data = response.json()

        # Extract followers and their reputation
        result = data.get('result', [])
        if not result:
            break
        followers.extend(result)

        # If there are fewer than 1000 followers in the result, we've reached the end
        if len(result) < 1000:
            break

        # Update start_account to fetch the next batch of followers
        start_account = result[-1]['follower']

        # Remove the last entry to avoid double-counting in the next iteration
        followers.pop()

    # Calculate follower count
    follower_count = len(followers)

    # Extract reputations
    reputations = [follower['reputation'] for follower in followers]

    # Calculate median reputation
    median_reputation = statistics.median(reputations) if reputations else 0

    return [follower_count, median_reputation]

if __name__ == "__main__":
    # Check if an account name is provided as a command-line argument
    if len(sys.argv) > 1:
        account_name = sys.argv[1]
    else:
        account_name = input("Enter the account name: ")

    result = get_followers(account_name)
    print(f"The account '{account_name}' has {result[0]} followers.")
    print(f"The median reputation of the account's followers is: {result[1]:.2f}")

And here is some sample output:

$ ./SteemFollowerStats.py remlaps
The account 'remlaps' has 1966 followers.
The median reputation of the account's followers is: 47.37
$ ./SteemFollowerStats.py remlaps-lite
The account 'remlaps-lite' has 709 followers.
The median reputation of the account's followers is: 47.84
$ ./SteemFollowerStats.py penny4thoughts
The account 'penny4thoughts' has 191 followers.
The median reputation of the account's followers is: 62.89
$ ./SteemFollowerStats.py steemitblog
The account 'steemitblog' has 39652 followers.
The median reputation of the account's followers is: 40.61
$ ./SteemFollowerStats.py realrobinhood
The account 'realrobinhood' has 227 followers.
The median reputation of the account's followers is: 67.20

And here is the ChatGPT transcript (at least until I delete it.)

I guess creating this code took about an hour from start to finish (including the false start on Google Gemini, and also fixing a bug that this exercise uncovered in my get_followers.sh script). I'm certain that it took me longer to write and proof-read this blog post than it did to create the code, itself.

Next up: I'll incorporate the logic above into my autovoter, in order to start biasing the rewards from my autovotes towards authors who make the effort to build strong follower networks. It's still not exactly clear to me how the number of followers and the median follower reputation should be weighted, so maybe I'll seek some help from the AI on that front, too. 😉

Previously in Steem for script kiddies, I posted:


Thank you for your time and attention.

As a general rule, I up-vote comments that demonstrate "proof of reading".




Steve Palmer is an IT professional with three decades of professional experience in data communications and information systems. He holds a bachelor's degree in mathematics, a master's degree in computer science, and a master's degree in information systems and technology management. He has been awarded 3 US patents.


image.png

Pixabay license, source

Reminder


Visit the /promoted page and #burnsteem25 to support the inflation-fighters who are helping to enable decentralized regulation of Steem token supply growth.

Sort:  

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

This post has been featured in the latest edition of Steem News...

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.032
BTC 60205.00
ETH 2994.41
USDT 1.00
SBD 3.90