Generate Community Report | Steem Discord Bot Python #8
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.
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.
- 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.
In the next lecture, we will learn how to create .txt and write the report.
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
Lecture #4: First Bot Command
lecture #5: Retrieving Steemit Account Information using SDS
Lecture #6: Implementing !info Command
Lecture #7: Discord Embed Reply with User Info
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