steem-python tips #4 - See who resteems your posts

in #steemdev6 years ago

Resteem


Resteem is defined inside a "custom_json" operation. It doesn't have a separated operation type. It's basically counterpart of "retweet", the concept you may be familiar with Twitter.

Condenser interface (Steemit) or other interfaces doesn't show that information that who resteemed your posts. Let's find out who supports our posts by resteeming.

Main Flow of the script

  • Go through the account history
  • Filter main post creations
  • Check resteemers and add them to a counter
  • Get an output with cool visualization

Since going through the history takes a lot of time, I have only analyzed my account's last 30 days. If you care to wait, you can just remove that check and get all history.

Script


from steem import Steem
from steem.account import Account
from steem.post import Post
from collections import Counter
import steembase
import pygal
def resteemers(steemd, username, output_path):
    processed_posts = set()
    resteemer_list = list()
    resteemed_posts = list()
    acc = Account(username, steemd_instance=steemd)
    for comment in acc.history_reverse(filter_by=["comment"]):
        # don't process updates
        post_identifier = "@%s/%s" % (
            comment.get("author"), comment.get("permlink"))
        if post_identifier in processed_posts:
            continue
        processed_posts.add(post_identifier)
        # don't process resteems of the author
        if comment.get("author") != username:
            continue
        try:
            post = Post(comment, steemd_instance=steemd)
        except steembase.exceptions.PostDoesNotExist:
            continue
        if post.time_elapsed().total_seconds() > 2592000:  # 1 month
            break
        # don't process comments
        if not post.is_main_post():
            continue
        resteemers = steemd.get_reblogged_by(
            post.get("author"), post.get("permlink"))
        resteemers.remove(username)
        if len(resteemers) == 0:
            continue
        for resteemer in resteemers:
            resteemer_list.append(resteemer)
            resteemed_posts.append(post.identifier)
    most_resteemed_posts = Counter(resteemed_posts).most_common(5)
    most_resteemers = Counter(resteemer_list).most_common(5)
    line_chart = pygal.Bar()
    line_chart.title = 'Most Resteemed Posts (%s)' % username
    for item in most_resteemed_posts:
        line_chart.add(item[0], item[1])
    line_chart.render_to_file("%s/most_resteemed.svg" % output_path)
    pie = pygal.Pie()
    pie.title = 'Resteemers of %s' % username
    for item in most_resteemers:
        pie.add(item[0], item[1])
    pie.render_to_file("%s/resteemers.svg" % output_path)
def main():
    s = Steem(nodes=["https://api.steemit.com"])
    resteemers(s, "emrebeyler", "/tmp/")
if __name__ == '__main__':
    main()

See the script nicely formatted at Github Gists.

Example Outputs


1. Most resteemed posts
Screen Shot 2018-03-06 at 10.11.12.png

2. Usual resteemers
Screen Shot 2018-03-06 at 10.10.35.png

Requirements


You need to have steem-python and pygal libraries installed in your local python environment.

Have fun.

Sort:  

Just tried it now. Works great. Thanks!!!

Ugh, another new concept to me. What does it mean to resteem? To post another person's content as your own - or with their names on it?

And is it a good thing when your content is resteemed?

To post another person's content as your own - or with their names on it?

Yes.

And is it a good thing when your content is resteemed?

Also, yes. Your content will gain more visibility since it will be also featured on the resteemer's feed.

I see. Thank you for clearing this up for me :)

So what is the benefit of reposting to the person who reposts?

For the reposter, there is no benefit. You repost and the content reaches a wider audience.

Thank you so much dude. It gave me lot of information. You are doing a great work. These accurate stats. Your blog is worthy. Keep it up

hey. bu çok faydalı bir paylaşım. sevdim

Coin Marketplace

STEEM 0.16
TRX 0.13
JST 0.028
BTC 55994.52
ETH 3002.48
USDT 1.00
SBD 2.12