Using Mastodon as a RSS Feed Reader

There are a number of blogs and serials that I really enjoy reading and (where available), I've tended to subscribe to their RSS feeds using Nextcloud News.

What I've noticed though, is that, amongst everything else I do on my phone, the new article notifications do tend to get lost. The result is that I quite often don't notice that a new post has been published unless I happen to see someone else toot it into the fediverse (for example, the prompt for this post is that I very nearly missed out on this great post).

Just under a year ago, I wrote a simple RSS to Mastodon bot to automatically toot links to my own posts.

Given that fediverse notifications are one of the things that I do look at fairly frequently, it occurred to me that it might be an idea to re-use my existing code base to stand up a "private" bot: it could monitor the RSS feeds that I care about most and publish a followers-only toot when something new appears. I'd then also be able to set Mastodon to always notify me when the bot tooted.

In this post, I talk about building a configuration to use my existing bot code to push new posts into my Mastodon notifications so that I (hopefully) never miss another great post.


Account Setup

I needed to create a new Mastodon account for this, but setup was pretty straight forward:

  1. Create a bot account
  2. Mint some API Creds
  3. Follow the bot from my main account

Screenshot of the Newsbot profile as viewed from my own account. I've followed the account and set Mastodon to notify when it toots

Because the intention was for this to be a private bot, I also set the bot to require follower approvals.


Configuration

Having created and followed the bot account, it was just a case of setting up some config so that a new container could be created using the existing bot image.

I created a directory for it to use for storing tracking hashes (these prevent the bot from continually re-tooting the same content)

mkdir -p newsbot/hashdir

And then created feeds.json to tell it which feeds to watch:

[
  {
    "FEED_URL": "https://neilzone.co.uk/index.xml"
  },
  {
    "FEED_URL": "https://webdevlaw.uk/feed/"
  },
  {
    "FEED_URL": "https://www.oglaf.com/feeds/rss/"
  },
  {
    "FEED_URL": "https://www.revk.uk/feeds/posts/default?alt=rss"
  },
  {
    "FEED_URL": "https://shkspr.mobi/feed/atom"
  }
  // etc
]

First Run

Although I'd tested by running the bot script on my local machine, I wanted to also test using a container on the box that the bot would ultimately be living on.

I didn't want to spam the fediverse with test runs, so I put the bot in dry-run mode so that it'd just print generated toots to screen:

docker run --rm \
--name="newsbot" \
-e DRY_RUN="Y" \
-e MASTODON_VISIBILITY="private" \
-e TRACKING_MODE="PERURL" \
-e MASTODON_TOKEN="$TOKEN" \
-e MASTODON_URL=https://mastodon.bentasker.co.uk \
-v /home/ben/docker_files/newsbot/feeds.json:/app/feeds.json \
-v /home/ben/docker_files/newsbot/hashdir:/hashdir/ \
registry.bentasker.co.uk/misc/python_mastodon_rss_bot:0.2

This took a long time to complete: some of the feeds cover their site's complete post history, rather than the last n entries (I might add a limiter later, but for now, it only actually needs iterating through once).

Then, in order to test, I removed a single hashfile

rm newsbot/hashdir/*/1fba76b61fd966a68b3c68cf45afcfd20bff3422

And re-ran the container without dry-run enabled:

docker run --rm \
--name="newsbot" \
-e DRY_RUN="N" \
-e MASTODON_VISIBILITY="private" \
-e TRACKING_MODE="PERURL" \
-e MASTODON_TOKEN="$TOKEN" \
-e MASTODON_URL=https://mastodon.bentasker.co.uk \
-v /home/ben/docker_files/newsbot/feeds.json:/app/feeds.json \
-v /home/ben/docker_files/newsbot/hashdir:/hashdir/ \
registry.bentasker.co.uk/misc/python_mastodon_rss_bot:0.2

The bot tooted and moments later, I received a notification:

Screenshot of notification from News Bot

So, I now just needed to wrap the invocation in a script for cron to trigger

#!/bin/bash
#
# Read RSS Feeds
# and toot new items

ignore_tags=""

docker run --rm \
--name="newsbot" \
-e DRY_RUN="N" \
-e MASTODON_VISIBILITY="private" \
-e TRACKING_MODE="PERURL" \
-e MASTODON_TOKEN="$TOKEN" \
-e MASTODON_URL=https://mastodon.bentasker.co.uk \
-v /home/ben/docker_files/newsbot/feeds.json:/app/feeds.json \
-v /home/ben/docker_files/newsbot/hashdir:/hashdir/ \
-e SKIP_TAGS="$ignore_tags" \
registry.bentasker.co.uk/misc/python_mastodon_rss_bot:0.2

Finally, I added an entry to crontab so that the bot would check feeds periodically

*/30 * * * * /home/ben/docker_files/cron/newsbot.sh

Conclusion

Treating Mastodon as a personalised news reader might be something of an odd choice but, for me, it makes sense as it's one of the things that I'm actually looking at quite regularly.

(mis)using the notification mechanism to alert me to posts should greatly improve the chances of me seeing the content that I want to read - one of the biggest issues I have with the Nextcloud News app is that its notifications only show a single item (the latest published), so it's easy to not see the stuff that you're missing.

Because I already had a bot, setting all of this up really was the work of minutes and should (hopefully) allow me to use hours more productively. In fact, the next issue is likely to be me finding that I don't actually have the time after all.