Steem-Python Word Count Bot for Curated Tags

This bot fetches all new posts with a specified tag from the Steem blockchain and counts the words of each post. The bot then leaves a comment on posts that fall below the specified word count.

steempybot.jpg

Why?

I wrote this bot for the @travelfeed curation project that I am part of. While #travel is spammed with many posts that consist of single photos which makes it hard to find good content, #travelfeed is for longer travel blogs only and has certain quality requirements, most importantly a minimum of 250 words. To enforce this, we have so far been using a word count browser extension and manually left comments on all short posts, but this is a really tiring job (especially with the 20 second limit on comments), so I wrote this script to automate it.

How?

The bot streams all new posts from the Steem blockchain. If "travelfeed" is set as a tag and it is not a comment, the bot checks if the post has previously been checked by the bot (relevant to prevent double comments) and if not, fetches the post body (markdown) and strips it of all elements that are irrelevant for the word count (markdown, weblinks, images) and adds it to the list of checked posts. Then a word count is performed, for all posts below 250 words a comment is left. If this comment fails (e.g. due to the 20 second limit), the bot retries after 19 seconds.

Proof of Work

I ran some tests in #travel today, you can see the resulting comments here (thanks to all the users who served me as guinea pigs!). The test run resulted in the following shell output:
travelfeed-testrun.jpg

I have set up a new account and am currently testing the bot in #travelfeed.

Python Packages

The bot is using steem-python. If you have never worked with steem-python before, check out the helpful @steempytutorials!

Apart from steem, the python packages bs4 and markdown are used by this bot to turn the markdown fetched from the Blockchain into plain text where then a word-count is performed.
You can install these packages with pip:

pip install -U bs4 markdown

Steem-Python Configuration

A working Steemit node is needed. For me, this configuration had the best results:

steempy set nodes https://gtg.steem.house:8090/,https://api.steemit.com

An account needs to be added to steempy:

steempy addaccount yoursteemitusername

The passphrase of the steem-python wallet needs to be accessible for the bot:

export UNLOCK='yourpassphrase'

Get the script on Github

Get the python script from Github and adjust the tag (set to travelfeed) and the steem-username (set to travelfeed-bot, 2x). Adjust all comments to be posted to the blockchain (posts.reply) and shell messages (print) to your liking.

You can run it with

python wordcountbot.py

Tip: If you would like to run the script permanently, I suggest to use tmux as described here

Roadmap

  • Modify the bot to run in #travel and instead of leaving a comment on posts with less than 250 words leave a comment on posts with above 250 words that don't use the tag #travelfeed yet to advertise TravelFeed. This could either be accomplished by an automated comment promoting travelfeed (limited to once per author) or by sending the post-link somewhere e.g. to a Discord channel for manual review by our curation team;
  • If a comment has failed, send the link to a Discord channel to add the comment manually;
  • Add an elseif ("elif") statement to check for each post before performing the word count if the post author is currently muted by @travelfeed (we mute all abusers and blacklist them from curation). In this case, a comment would be posted asking the author to not post in #travelfeed and with a link to our Discord where they could ask about the reason for them being blacklisted. However, I could not find any steem-python function to check if a user is muted by an account, maybe someone can help me if there is a function like this?;
  • Output the log into a file instead of the shell;
  • Resolve the error messages that I currently don't understand (TypeError, UnboundLocalError);
  • Improve error handling.

How to Contribute

Please get in touch with me on the Steemit Travellers Discord (home to @travelfeed) or the Steem Dev Discord if you would like to contribute to this project or feel free to reuse the code as you please.


Check out my Recent Posts

By the time you read this, this post or some of the posts below may be older than 7 days so you can not vote for them anymore. If you want to support me, please consider voting on one my recent daily posts!

You can view all my posts on steemitworldmap.com!

Please Follow, Upvote and Resteem

If you like my content, don't forget to upvote this post and follow me for more photos and travel stories! Also, I will be happy if you leave a comment to tell me your thoughts and resteem this post to share my work!
All my photos are also available for licensing, please contact me through my Website or the Steemit Traveller's Discord.

Tag #travelfeed in your travel posts (min. 250 words) for a chance to be curated!

Transparent-Discord-Travel.png



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
23 Comments
Ecency