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.
Installing Steem-Python
I have to say I feel bad for bothering @themarkymark on this post with stuff but I truly have to say that his tutorial is seamless in doing the job. So rather than write something written millions of times before I am just going to send you to the post by our great Malcolm Reynolds Witness. My apologies, after reading his post I went back and rewatched Firefly, sch a good show. Now I like this tutorial more than most as it is very very simplistic. By the way, I am doing everything on ubuntu 16.04 (will update to ubuntu 17.XX throughout this tutorial though) and will not be testing anything on windows because... I do not actually have a computer that has a windows OS on it.Wallet
For simplicity and so that I do not have to worry about keys as much. We are going to use the steempy BIP38 encrypted wallet to hold out keys. First thing is first, once everything is installed is to go into your wallet and change wallet password with the following command ```steempy changewalletpassphrase``` Now follow the instructions. Once you have a passphrase on your wallet, import your account with password: ```steempy importaccount [account name]``` Then follow the instructions. Great now we can continue on to explain how to make the most very basic of voting bots!Now this program doesn't require you to actually have your posting key imported to the wallet, as this is going to be the very very basic on how to vote. So the program we are going to build is going to work as follows, upon startup we will be asked to enter an account and private posting key, it will save those as variables and use them for later. Next the program will wait for you to give it a URL to a post you want to upvote. Upon entering a URL it will request you enter a number between -100 and +100 as the voting weight (negative weights will flag/downvote the post) After you enter that data it will go and vote on the post at the requested value.
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)
Now while this program isn't useful as it, what it is is the basis for many voting bots whether they be bidbots or not. Later I will go into a better way at getting the ```author/permalink``` from a URL (although I believe it does it the same way) and I will go through a simple method to get the bot to find the URL of the post on its own so you do not have to keep feeding it the posts. The point is, this is going to be the basic starting point for our voting bot most of the time and it is simple to make. I believe this post fits into either technology or engineering for STEM which is why it has the steemstem tag.
Installing Steem Python: steemit.com/programming/@themarkymark/how-to-install-steem-python
Python String Documentation: docs.python.org/3/library/stdtypes.html
Image Source: commons.wikimedia.org/wiki/File:Python3-powered_hello-world.svg
Image Source 2: commons.wikimedia.org/wiki/File:Steemit-big.png
Do you enjoy reading or writing topics related to STEM (Science, Technology, Engineering, and Mathematics) then I would suggest checking out @steemstem! They do wonderful work curating the best STEM related posts on Steemit. For more information check out the SteemStem chat room on steemit.chat or check out their Guidlines and start writing.
Very clear and useful post! I will include it in my best of Steemit roundup. Especially grateful because I wanted to create an upvote script - excellent timing :)
If you are planning on making an upvote script, I can give you more, better, information as this is going to be a series of posts in an attempt to show people some of the hacky ways that I made my bot and the problems I went through to make it. I would tell you to read the documentation for steem-python but... most of it either has nothing on usage or no description at all and it is very very... limited in my opinion. I am certain I am not alone in saying that if you have experience with programming it would probably be better to ask someone directly over reading that documentation.
Thanks for creating this tutorial as well as for creating the steemstem bot. I am planning to write a lot of STEM related posts and will surely use steemstem service.
If you follow these tutorials you will soon learn that it isn't very difficult to make the steemstem-bot :D
Very nice, i look foward to seeing more from you. I think more should learn it and they should dev for the steem blockchain.
Well I am writing this kind of as I learn so I cannot guarantee much, but I did run into a lot of difficulties when attempting to learn this material that I will hopefully spare others.
I understand completely. I have had a lot of issues but am learning when I have the time. If I can help you let me know. Ill be watching and learning as you post your experience as well.
I think I have a lot of things figured out. I am going (in my 3rd) to post a very hacky way to follow the trail of an upvote of someone (so if they upvote something you can do something about it) however it is very hacky and in the 4th will have a much much better way to do it. I just really enjoy the technique and find it super entertaining.
Excellent tutorial for the construction of SteamSTEAM Bot, I will follow each one of the tutorials.
hallo steemians world good night greetings my member steemit indonesia help on upvote & follow yes!..
i want to learn a lot from you about steemit in upvote sharing?