Steemit-Python-Bot | Part 2: How to return a list of the people who upvoted your post

in #utopian-io7 years ago (edited)

Introduction

In this series I will share my experience of building a Steemit bot with the python library. I'll post my functions used as a basis for my bot and try to explain it. The final goal will be to develop a high level API build on top of the Steem-Python library to make bot development easy.

Requirements

1. Python 3.6
2. steem-python

I personally use Windows and it was quite challenging to install the library but this tutorial helped me a lot.

The Code

1. Setup

image.png

Just like in the last tutorial we need to import the library and initialize the Steem class.

2. The function

The new function get_voter() basically uses the already existing get_active_votes function but makes it easier to use.

image.png

The old function takes two inputs and we will combine these into one input ("post_identifier") and later split them into two again.

image.png

After excuting the function, it returns a list like stated in the offical documentation.
image.png

image.png

In this example we only want the username of the upvoters but you could also extract other usefull informations like the voting weight.

To isolate this information we need to create a new empty list voter = [] and then add the value of 'voter' to it, every step of a for loop.

image.png

But before we return the list in the next line we filter out our own upvote in line 13. This will prevent possible further errors with double votes.

image.png

3. Execution

image.png

The executed function will return a list like this:

image.png

As mentioned earlier you only need to provide one argument:

image.png

How to get the "post_identifier"

In my first tutorial I already explained how to get the newest post of a user. We can use a faster and updated version of this code to get the "post_identifier" (Thanks to @emrebeyler!).

image.png

Final Code (Pastebin.com)

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Hey, first I want to let you know, I saw your bot gave me test upvote. As long as I'm getting upvotes it is working, if I don't get an upvote, it is broken! ;-)))

On a more serious note, thanks, that you are adding in your tutorial json output, so we can see exactly where is the data you are extracting. How do you get such a nice output? In my case everything is clobbered in one long multi line and I can't make the sense of it. What tool do you use?

One more thing, your tutorials are well thought, with plenty of important information that beginners and wanna-be like me needs it, good job and I hope you continue ;-)

Thanks for the feedback! :)

To get a readable output I use python's build in module pprint.

  1. import pprint
  2. pprint.pprint(your_json)

O cool, thanks will thy this out!

Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.21
TRX 0.26
JST 0.040
BTC 101854.93
ETH 3674.01
USDT 1.00
SBD 3.18