Introduction
In this series I will share my experience about 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.
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
We need to import the library and initialize the Steem class.
2. The function
In order to understand the function we need to know how a post looks like on the Steem Blockchain.
In my knowledge a post isn't labeled "post" but with a two tricks we can identify one:
- A post functions just like a comment (labeled "comment").
- A post always has a title and a comment never has one. Therefore we can look if the title isn't empty.
--> Now we can just extract the "permlink" to get the link to the newest post and return it.
3. Execution
We obviously need to provide a username in form of a string to execute the function properly.
Possible Errors
- If the function returns
None
, the user hasn't posted something yet or we didn't find a post because we looked at too few entries in the "account history" of the user.
This is the default limit ("entries to scan"). Raise it if necessary.
- If this error occurs:
A: You entered a wrong user name.
B: The limit is to high, just lower it.
--> to fix some errors with the limit I added:
The error will simply get ignored.
But now you won't get an error if your username is wrong. Delete these extra lines if you want the error to occur.
Final Code (Pastebin.com)
Posted on Utopian.io - Rewarding Open Source Contributors