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
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.
The old function takes two inputs and we will combine these into one input ("post_identifier") and later split them into two again.
After excuting the function, it returns a list like stated in the offical documentation.
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
.
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.
3. Execution
The executed function will return a list like this:
As mentioned earlier you only need to provide one argument:
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!).
Final Code (Pastebin.com)
Curriculum
Posted on Utopian.io - Rewarding Open Source Contributors
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
.import pprint
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]