steem-python tips #4 - See who resteems your posts
steemdev·@emrebeyler·
0.000 HBDsteem-python tips #4 - See who resteems your posts
<img src="https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drxhdemuq4r4ezSCFC6xhAknvQspB_1680x8400"> #### 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](https://gist.github.com/emre/c2f3a0552866a2f877fa0a6588bd5ac0). #### Example Outputs *** **1. Most resteemed posts**  **2. Usual resteemers**  #### Requirements *** You need to have **steem-python** and **pygal** libraries installed in your local python environment. Have fun.
👍 emrebeyler, ody18, pars11, foysalahmedtopu, turbot, muhammetcan, yucealiosman, gokos, onursa, testorz, steem-rocks, selamtux, samedb, cement3, qustodian, evilest-fiend, sambillingham, promobot, tolgahanuzun, privacybydesign, cutemachine, espoem, jumbot, sbdraffle, sauronbey, ucmuharfli, embesilikat, eshapunver, firster78, teamhumble, dangerux, oendertuerk, crokkon, omersurer, intelligencer, esme-svh, lastozgur, ethemkibar, msp3k, nettybot, feronio, brotato, dootdoot, matrixonsteem, steemliberator, witnessstats, r2steem2, steemcreate, thashadowbrokers, pizaz, triplethreat, wewt, conflaxus, tittilatey, cajun, coonass, squirrelnuts, steemdevs, jeezy, test.with.dots, pi-pi, listentosteem, gravy, zoltarian, ripperone, ewq, steemlore, ogergami, boontjie, damla, properfraction, osmania, longtimenosee, xeniaioannou, hakancelik, olegn, freemessage, crpytoanalyzer, siklosi, ahmetmertugrul, howo, revan746, pokeparadox, favcau, sndbox, world-travel-pro, hansikhouse, voronoi, alfarisi, heriafriadiaka, erb, luvabi, leotrap, ponpase, osm0sis, playitforward, berkaytekinsen, rjrudillas14, blockmountain, lgm-1, mindfreak, coquiunlimited, somethingburger, archual, mineopoly, longming, sizranoy, maapeldek, busy.org, andybets, patrici,