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

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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now