Updates for Bot for Curated Tags (travelfeed-bot)

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@jpphotography·
0.000 HBD
Updates for Bot for Curated Tags (travelfeed-bot)
**I wrote this bot to help our curation with @travelfeed / #travelfeed, but it can be modified for use in any other curated tag that has certain criteria for participation. For each new post in the specified curated tag, the bot first checks if the author is black- or whitelisted. If this is not the case, it processes the post contents and checks if the language is English and if the word count is above the specified limit. It then leaves appropriate comments if a rule break is detected. You can find the introduction post [here](https://utopian.io/utopian-io/@jpphotography/steem-python-word-count-bot-for-curated-tags) and the Github repository [here](https://github.com/tiotdev/steempy-wordcountbot).**

![U5drvbcymxTveHzb7CH5jBaenZXMRkv_1680x8400.jpeg](https://cdn.utopian.io/posts/40c625f6154c465d1533ed4d6d4df671fc2cU5drvbcymxTveHzb7CH5jBaenZXMRkv_1680x8400.jpeg)

---

## New Features
### [Added Blacklist](https://github.com/tiotdev/steempy-wordcountbot/commit/74b60c0aa13d098add2665d0122a3ba7311c7bac)
If we find plagiarism in posts in #travelfeed, we exclude these users from future curation by muting them on Steemit. I implemented a function in the bot that grabs the list of muted users from the Blockchain and checks if a user is muted previous to processing the posts content. If this is the case, no other checks are performed and a specified blacklist comment is left.

![blacklist.jpeg](https://cdn.utopian.io/posts/01a5c9bba2e85d99b2fe6b770dbc7d46d639blacklist.jpeg)

### [Added Whitelist](https://github.com/tiotdev/steempy-wordcountbot/commit/b7e50af8f8b2f2753f542cf9cc04963c392df1c0)
Since there is a bot (?) publishing automated posts in #travelfeed that fall short of 250 words and I did not want the bot to leave a comment each time, I wrote a simple whitelist function. Posts of users specified in the whitelist will never be checked nor receive a comment, the loop jumps to the next post.

![whitelist.jpeg](https://cdn.utopian.io/posts/6c5f70b946abccfc96bb72dabc6e0504d6b9whitelist.jpeg)

### [Added Language Detection](https://github.com/tiotdev/steempy-wordcountbot/commit/353e6cdadfa05af744ba9c6ec73b7bdae64beae3)
For posting in #travelfeed, one of our requirements is to use at least 250 words in English. Despite that, we are receiving multiple posts per week that are written in another language. Using the `langdetect` library, I implemented a language check. At the moment the check has issues with bilingual posts that have more than 250 words in English, but even more in a different language, but I plan to fix this (see roadmap).

![langdetect.jpeg](https://cdn.utopian.io/posts/8e9aad358f8b7eb09327c2fd88463dfbb48alangdetect.jpeg)

### [Added Configuration Variables](https://github.com/tiotdev/steempy-wordcountbot/commit/74b60c0aa13d098add2665d0122a3ba7311c7bac)
In the first version of the bot, all adjustments had to be manually made within in the code, which was especially annoying for repeated changes. I now added variables and a configuration section on top of the script.

![configuration.jpeg](https://cdn.utopian.io/posts/b19b24ade56edce657fbe439258fa14c9cf5configuration.jpeg)

---

## Bug Fixes
### [Recursive Exception Handling](https://github.com/tiotdev/steempy-wordcountbot/commit/c48c28a3239600ce0fb572876dac74033d3d2fca)
##### Issue:
The first version of the bot contained some code where exceptions were not handled properly. Since the public RPC nodes are completely overloaded at the moment and often return empty values resulting in TypeErros or AttributeErrors, this could sometimes lead to the bot crashing.
##### Fix:
I added proper exception handling. If an exception occurs, the function recursively calls itself and reconnects to the blockchain from the last processed block.

![handleexceptions.jpeg](https://cdn.utopian.io/posts/1874de1793b2b585b10d7479717cfc32e16dhandleexceptions.jpeg)

### [Automated Node Switcher](https://github.com/tiotdev/steempy-wordcountbot/commit/b7e50af8f8b2f2753f542cf9cc04963c392df1c0)
##### Issue:
Related to the previous issue. If the primary node was down (RPCError) or returned too many empty values, steem-python would not automatically switch to the second node in the list and I had to manually switch nodes in the CLI and restart the bot.
##### Fix:
On each call of the recursive function, one out of four node-lists is randomly selected.
After I had implemented the node switcher, the number of bot crashes got a lot lower, but if all nodes are down at the same time, the system load of the script when repeatedly attempting to reconnect for several minutes is too high and it is killed by the system. Since the public RPC nodes are slow as sh*t and return a lot of empty values, I plan to migrate the code to beem where node handling is better. If that doesn't work, only a private node could help.

![nodeswitcher.jpeg](https://cdn.utopian.io/posts/cae2afa404a3391daa6a482e91876f8f4febnodeswitcher.jpeg)

### [Logging Processed Posts Permanently](https://github.com/tiotdev/steempy-wordcountbot/commit/3bc046344358bb56ccbe52125415377e6b3fff42)
##### Issue:
The list of processed posts was cleared when restarting the script, this could lead to double comments on previously commented posts that were updated after the bot had been restarted.

![doublecommentissue.jpg](https://cdn.utopian.io/posts/96d64d4b262fb9f88c4d644317af0f54fac4doublecommentissue.jpg)
##### Fix:
Instead of adding processed posts to a list, they are now saved to a file which is then read into a list.

![handlefiles.jpeg](https://cdn.utopian.io/posts/ea945ec5bc522cee128a168f429f5618c86fhandlefiles.jpeg)

---

## Roadmap
* I am working on a Web UI accessible to the rest of the @travelfeed curation team to view the logs and restart the bot;
* Migrating the bot from `steem-python` to `beem`, an alternative python library for Steem created by @holger80;
* Removing false positives in language detection of bilingual posts by using `detect_langs` instead of `detect` from the `langdetect` library and multiplying the percentage with the total number of words counted;
* Integrating some code that I am currently testing for the @de-travelfeed curation project;
* Leaving comments on all valid posts showing the user stats (number of total posts in travelfeed, number of posts that received a full and partial upvote), inspired by @photocontests by @juliank.

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@jpphotography/updates-for-bot-for-curated-tags-travelfeed-bot">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,