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
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @deathwing, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Great tutorial to newbys like me @wil1liam .
This looks something easy enough that even I could try ;-) Thanks for the code.
Then next step would be, to create a 'very important' list of posters that you would want to follow closely and you pass that list into your function and get their last 2-3 posts, so you make sure you don't miss any. I will try this today. And maybe one day also email notification and code running every say 10-15 minutes on raspberry pi ;-)
I suggest using
get_discussions_by_blog
which is more efficient since you don't need to check for all operations of a user.This contribution belongs to "tutorials" category. Can you please edit the contribution and change it?
[utopian-moderator]
changed it. sorry for the inconvenience
Hey @wil1liam I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x