Generate Community Report | Steem Discord Bot Python #8

in Steem Devlast year

Welcome back, developers.

Greetings to all Steem enthusiasts! Today, we will learn how to generate a report for a community. We will utilize the SDS API to obtain the total number of active posts, comments, and unique comments.

lecture8.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. We also learned how to create functions and retrieve data using the requests library in 5th lecture. We implemented the !info command in 6th lecture which is used fetch the information of any steem user. In the 7th lecture, we learned how to send an embedded message with columns, images, and a profile image.

Procedure
  • First, we must create a function get_community_report in steemfun.py. We will call an SDS API and return the response as described here.
 async def get_community_report(self, community):
        api = self.utils.sds_base + f"/feeds_api/getActiveCommunityReport/{community}"
        response = requests.get(api).json()
        return map_sds_response(response)
  • Now we need to add a command !report in utils.py file.
# bot commands
self. commands = ['!info', '!report']
  • After adding the command to the list, we need to set it in the main.py file. This command requires two properties. The first one is the command itself, and the second one is the community for which we want to generate the report.

image.png

  • We can now call the get_community_report function from instances of steemfun.py and pass the extracted community as an argument. Let's print the output. I am not sending it as a message since a long message cannot be sent using the bot. We need to create a .txt file and attach it. We will learn how to attach a file in the next lecture.
 # !report command
        if command == utils.commands[1]:
            if len(props) >= 2:
                community = str(props[1]).lower().replace('@', '')
                community_report = await steemfun.get_community_report(community)
                print(community_report)
  • Run the project, use the command, and check the console.

image.png

In the next lecture, we will learn how to create .txt and write the report.

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