Retrieving Steemit Account Information using SDS | Steem Discord Bot Python #5

in Steem Devlast year

Welcome back, developers.

Greetings to all Steem enthusiasts! Today, we will learn how to write a Python function that fetches Steemit account information. This function can be used in any part of our project, making it a valuable practice to create reusable code.

lecture5.png

Summary

We established the necessary environment for developing a Python-based Discord bot during our first lecture. In our second lecture we create a discord bot token, configure the bot and generate the invite link. We used the invite link and added the bot to our server. In our third lecture, we will bring the Community-Bot online in our local environment.

In the 4th lecture, we successfully developed our initial bot command, !info. Today, our main goal is to retrieve Steemit account information by utilizing the SDS Account API.

Procedure
  • First of all, create a new file steemfun.py, We will use this file to write all the functions in it. Import also creates an instance of **Utils **in the **SteemFun **class as shown here.

image.png

  • Now first we need to set the base URL of the SDS API in our utils.py file.
self.sds_base = 'https://sds0.steemworld.org'

image.png

  • We need to install the requests package to fetch the data over the network. type pip install requests in the PyCharm terminal and press enter. Make sure you have a stable internet connection.

image.png

  • create a async function get_account_ext in SteemFun class and fetch data from the sds account API as describe here. We will add a parameter in the function username to get data for this user. Print the response to check if our function is working properly or not.

    async def get_account_ext(self, username):
        if username is None:
            return
        else:
            api = self.utils.sds_base+ f"/accounts_api/getAccountExt/{username}"
            response = requests.get(api).json()
            print(response)

image.png

  • Our function is ready to use. Now we need to go to the main.py file and create an instance of SteemFun and call our function in the !info command.

image.png


# !info command
        if command == utils.commands[0]:
            await steemfun.get_account_ext('faisalamin')

image.png

  • Run the bot and type the command !info in Discord. You will see data in the PyCharim logs as shown here.

image.png

  • In our upcoming lecture, we will streamline the SDS API response using a dedicated function and transmit the data through a Discord message. Stay tuned.
Github
Steem Discord Bot Series
SteemPro Official

Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Cc: @pennsif
Cc: @future.witness
Cc: @stephenkendal
Cc: @justyy


Best Regards @faisalamin

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60305.38
ETH 2447.61
USDT 1.00
SBD 2.51