Get RSS Feeds on Mastodon

Anyone who has made the switch from Twitter to Mastodon may notice that some news sources are still missing here. One way to get them into the Fediverse is to use an RSS Feed via a Mastodon bot. This guide shows you how to display RSS Feeds with feed2toot Mastodon.

I will publish the RSS Feed on my own Mastodon server. If you want to know how to run your own Mastodon, here is a instruction by me. Of course you can also do this on any Mastodon server.

Requirements

This guide assumes a few things:

  • Running Linux operating system, in my case Gentoo
  • Installed Python interpreter with VENV extension
  • PIP Installer
  • Cron Daemon
  • A Mastodon account to which the RSS Feed will be transferred to

You should install the packages listed above with the respective package manager of your distribution used.

Create virtual environment

In this tutorial I use the feed2toot bot written in Python. In order not to “compromise” my Gentoo system with software that is not present in the package manager, I use a virtual environment in Python.

First, let’s specify a location where we want to install this:

mkdir -p /opt/feed2toot

You are free to choose a different location, but remember to adjust the paths accordingly as the instructions progress.

Now let’s create the virtual environment:

python3 -m venv /opt/feed2toot

Create user and change permissions

When running anything on a Linux server, you should always create an extra user for it:

useradd -m -s /bin/bash feed2toot
chown feed2toot:feed2toot -R /opt/feed2toot

Enter virtual environment

Now it’s time to enter the virtual environment:

su feed2toot
cd /opt/feed2toot
source bin/active

Install Feed2toot

Now let’s install our feed2toot bot in the virtual environment:

pip3 install feed2toot

Register Feed2toot on Mastodon instance

For this step, you should already have created a Mastodon account because we need it now. We will now register our bot on the Mastodon instance.

register_feed2toot_app

This will walk you through the setup process where you need to enter a few things:

ParameterDescription
Mastodon instance URLEnter the Mastodon instance you want to use here
Mastodon loginYour login on the instance defined above
Mastodon passwordThe password for your login

You’re done with entering the above parameters.

Generate configuration file

The previous step created two files in the current directory. It makes sense to move these from the virtual environment to another location, because they would be lost when this environment is updated.

I chose the user’s home directory. If you plan to use multiple RSS feeds with different Mastodon users, you should then move each of them to a separate subfolder.

mkdir -p /home/feed2toot/feed1
cp feed2toot_clientcred.txt /home/feed2toot/feed1/
cp feed2toot_usercred.txt /home/feed2toot/feed1/

Now we create the necessary configuration file for this RSS Feed:

nano -w /home/feed2toot/feed1/config.ini

We add the following content:

[mastodon]
instance_url=https://mastodon.social
user_credentials=/home/feed2toot/feed1/feed2toot_usercred.txt
client_credentials=/home/feed2toot/feed1/feed2toot_clientcred.txt
; Default visibility is public, but you can override it:
; toot_visibility=unlisted

[cache]
cachefile=/home/feed2toot/feed1/cache.db
cache_limit=1000

[lock]
lock_file=/home/feed2toot/feed1/feed2toot.lock
lock_timeout=3600

[rss]
uri=https://www.example.org/rss
toot={title} {link}

[hashtaglist]
several_words_hashtags_list=/home/feed2toot/feed1/hashtags.txt

You should adapt the “instance_url” parameter to your desired Mastodon instance. In the RSS section, fill in the “uri” parameter with the desired link to the RSS Feed.

If you always want to add certain hashtags to the posts, create a file “hashtags.txt” in the same directory as the configuration file, otherwise comment the line with “;” out.

A detailed explanation of all settings can be found here.

Test function

Now let’s test if it works:

feed2toot -c /home/feed2toot/feed1/config.ini

Now the first feeds should arrive on Mastodon, otherwise check all data again!

Automatic update of RSS feed

Since this is working now, let’s take care of an automatic update via cron job.

First we create a script that we can simply run. I put this in the appropriate feed directory:

nano -w /home/feed2toot/feed1/refresh.sh

And add the following content:

#!/bin/bash
cd /opt/feed2toot
python -m venv .
source bin/activate
feed2toot -c /home/feed2toot/feed1/config.ini

Now let’s make the file executable:

chmod +x /home/feed2toot/feed1/refresh.sh

Now we only have to create a cron job:

crontab -e -u feed2toot

The content for this:

*/15  *  *  *  * /home/feed2toot/feed1/refresh.sh

This cron job will automatically update the RSS Feed every 15 minutes.

Update

Feed2toot

To update feed2toot we need to do the following:

su feed2toot
cd /opt/feed2toot
source bin/activate
pip3 install --upgrade feed2toot

Python VENV

If a Python update happened on the system, we have to do the following:

su feed2toot
cd /opt/feed2toot
rm -r *
python3 -m venv /opt/feed2toot
source bin/activate
pip3 install feed2toot

Conclusion

Thanks to the developers at feed2toot, running an RSS feed bot for Mastodon is a simple matter. I hope this guide has helped you!

Comments

You can use your Mastodon account to reply to this Post.

Reply