Steemit-Python-Bot | Part 1: How to find someone's newest post

in #utopian-io7 years ago (edited)

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

image.png
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.
image.png
In my knowledge a post isn't labeled "post" but with a two tricks we can identify one:

  1. A post functions just like a comment (labeled "comment").
  2. 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.
    image.png
3. Execution

We obviously need to provide a username in form of a string to execute the function properly.
image.png

Possible Errors

  1. 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.
    image.png
    This is the default limit ("entries to scan"). Raise it if necessary.
  1. If this error occurs:
    image.png
    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:
image.png
image.png
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

Sort:  

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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