Retrieving Steemit Account Information using SDS | Steem Discord Bot Python #5
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.
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.
- 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'
- 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.
- 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)
- 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.
# !info command
if command == utils.commands[0]:
await steemfun.get_account_ext('faisalamin')
- Run the bot and type the command !info in Discord. You will see data in the PyCharim logs as shown here.
- 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 |
---|
Lecture #1: Develop a Discord bot for your Steem Community
Lecture #2: How to Add a Bot to Your Discord Server
Lecture #3: Bring the Steem Discord Bot Online | Steem Discord Bot Python
Lecture #4: First Bot Command | Steem Discord Bot Python
SteemPro Official |
---|
Download SteemPro Mobile
https://play.google.com/store/apps/details?id=com.steempro.mobileVisit here.
https://www.steempro.comSteemPro Discord
Official Discord Server
Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Cc: @pennsif
Cc: @future.witness
Cc: @stephenkendal
Cc: @justyy
Best Regards @faisalamin