Generate Author Report for Community | Steem Discord Bot Python #10

in Steem Devlast year

Welcome back, developers.

Greetings to all Steem enthusiasts! Today, we will learn how to generate a single-author report for a community. We will utilize the !report command but with varying props length.


lecture10.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. In lecture 8th we learn how to generate a report for the community. In lecture 9th we learned how to develop a report and create a text file, then attach it to a Discord bot.. In today's lecture, we will learn how to get single-author report for a community.

Procedure
  • First, we will create a function in the steemfun.py file to retrieve and return a single author report using the SDS API. This function will utilize a specific API to fetch the report for a particular user. It will require two parameters: the username and the community for which we want to generate the report.
async def get_author_report(self, username, community):
        api = self. utils.sds_base + f"/feeds_api/getActiveCommunityAuthorReport/{community}/{username}"
        response = requests.get(api).json()
        author_report = map_sds_response(response)
        return author_report
  • Now we need to configure the !report command for three properties. The first property will be the command itself, the second property will be the username, and the third property will be the community account.

                      if len(props) == 3:
                await message.channel.typing()
                username = str(props[1]).lower().replace('@', '')
                community = str(props[2]).lower().replace('@', '')
                author_report = await steemfun.get_author_report(username, community)
                embed = discord.Embed()
                profile_url = utils.steemit_base + '/@' + username
                user_avatar = 'https://steemitimages.com/u/' + username + '/avatar/small'
                embed.set_author(name=username, url=profile_url, icon_url=user_avatar)
                embed.add_field(name='Posts',value= author_report.get('total_post_count'))
                embed.add_field(name='Comments', value=author_report.get('total_comment_count'))
                embed.add_field(name='Unique Comments',value= author_report.get('unique_comment_count'))
                await message.reply(embed=embed)
  • We need to make a correction. We will check for exactly two props and three props. Don't use the greater than or equal sign.

image.png

  • We created an embed message with the username. avatar and 3 fields.

image.png

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

Sort:  

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60638.91
ETH 2449.26
USDT 1.00
SBD 2.52