This post expects a very basic understanding of python syntax. This is going to introduce concepts of the steem-python library slowly at first to allow people to understand how to program their own stuff.
This is going to be a multipost series that may never end. I am writing this as information that I learned while writing @steemstem-bot, and then rewriting it because piston-lib is completely depreciated as it has no functionality to connect to https rpc nodes (https://nodename) and instead can only connect through web sockets (wss://nodename). This is going to be structured as a tutorial on building the basics of the library to the more complex. Each post will cover some specific content and will hopefully give someone the knowledge to build a bot with limited to no python knowledge. Now when doing this, I am programming everything twice, first on my main machine using the official library here and then secondly I am using a slightly modified version of the library here. Unless specified, the code should work with either one, if the code doesn't work for both then it will work for the Netherdrake library.
First for making this program we will need the Steem() module and the Post() module. The steem module is a higher level module that allows interfacing with the blockchain and the post module allows for yo to vote, post, reply etc to the blockchain.
Initializing the steem module is done with the following syntax:
class steem.steem.Steem(nodes=None, no_broadcast=False, **kwargs)
Now you can initialize the steem module as simply as:
s = Steem()
because the wallet actually has default nodes set, no_broadcast is set to false, and **kwargs can be defalted or set later.
The steem module works by contacting a lower level module called steemd which is why in our program we pass a keys=posting_key to it as the steemd module actually makes an instance specific to a posting key. Now we require this module as the Post module requires a steemd instance to work, to interface with the blockchain.
The post initialization looks a lot simpler.
steem.post.Post(post, steemd_instance=None)
where steemd_instance is passed in from the steem module above and the post is actually in the format: author/permalink
So the argument we would pass to get the post mentioned by themarkymark would be:
themarkymark/how-to-install-steem-python
And the URL is
https://steemit.com/programming/@themarkymark/how-to-install-steem-python
But since we are lazy and we want the program to remove thehttps://steemit.com/programming/@so that we can simply copy the URL without problem. We also want it to work if it were on another website like say chainbb, or busy.org. Since the URL follows the same pattern: website/category/@author/permalink we can simply use python to find at what position the '@' character is located and replace that part of the string.
string.find('@') #returns an integer location of where this is in the string
string.replace('original', 'new') #replaces the substring 'original' with the substring 'new'
So if you just want the code, copy this and save it into a file with a '.py' extension. So if I named it 'manual_voter' then the filename would be 'manual_voter.py', remember, without the single quotes.
To run it just go to your terminal and type: python manual_voter.py
from steem import Steem
from steem.post import Post
def loop():
account = input("Enter Account: ")
posting_key = input("Enter Key: ")
s = Steem(keys=posting_key)
while 1:
link = input("Enter Link: ")
link = link.replace(link[0:int(link.find('@'))],'')
vw = float(input("Enter Voting Weight: "))
pst = Post(link, s)
pst.vote(vw, account)
print('Voted!')
loop()
The output should look as follows:
Enter Account: opticcncfan
Enter Key: 5Kj###################################
Enter Link: https://steemit.com/programming/@themarkymark/how-to-install-steem-python
Enter VW: 25
Voted!
Enter Link:
Now for you it shouldn't actually black out your posting key. I am doing that as I am not giving away the posting key to that account. Now if you check steemd for opticcncfan you will find it has upvoted that post by themarkymark by 25%
Now for a slightly modified version of the bot (so I do not have to actually black out the posting key it uses the wallet)