Automatically publish RSS feeds on Mastodon
Many blogs and news websites share information about new articles and posts on various social media platforms like Twitter, Facebook, or Threads. Unfortunately, Mastodon is often not yet a target for these cross-postings.
Since I personally enjoy using Mastodon as a news source and aggregator for various blogs, I developed an application that automatically publishes RSS feeds in the Fediverse.
The source code and instructions for use are available on GitHub: https://github.com/davull/FeedToMastodon
A running instance of the application publishes posts from several news feeds on https://feedmirror.social
Feed To Mastodon
Feed To Mastodon
is a .NET application that automatically posts new feed entries to Mastodon. It supports RSS, Atom and RDF feeds. The application can be compiled and run locally or used as a pre-configured Docker image.
The application can handle any number of feeds. A separate Mastodon account can be used for each feed.
To prevent the respective Mastodon account from being flooded with old feed entries, previous entries are skipped during the first synchronization of a new feed, and only new entries are published.
Configuration
The configuration of the feeds to be monitored is done in a .ini
file.
[heise.de]
feed_url = https://www.heise.de/rss/heise-atom.xml
summary_separator = [...]
mastodon_server = https://mastodon.social/
mastodon_access_token = AWWHkaIB_...
[wired.com]
feed_url = https://www.wired.com/feed/rss
mastodon_server = https://mastodon.social/
mastodon_access_token = ABC...
...
In addition to the URLs for the feed and the Mastodon server where the target account is registered, an access token is required.
The summary_separator
parameter is optional and can be specified to shorten feed entries. The entry will be truncated at the first occurrence of the separator.
For example, if a post contains […]
, the entry can be shortened here:
Earlier today, we reported that […]
To the post <a rel="nofollow" ...>http://news.com/123</a>
Configuring summary_separator = […]
results in the shortened entry:
Earlier today, we reported that ...
Posted entries are stored in an SQLite database to prevent duplicate posts.
Mastodon access token
An access token can be generated via the Mastodon website under Preferences
-> Development
-> New application
. In the Name
field, you can enter any text, such as Feed to Mastodon
. For the Redirect URI
, the default value urn:ietf:wg:oauth:2.0:oob
can be kept. Under Scopes
, only write:statuses
needs to be selected, and profile
can be deselected.
After saving, you can click on the newly created application again and copy the access token under Your access token
.
Parameters
Parameter | Description |
---|---|
feed_url | URL of the feed, required |
summary_separator | Separator where the summary is cut off, see below, optional |
mastodon_server | URL of the Mastodon server, required |
mastodon_access_token | Access token for the Mastodon account, required |
The file paths for the configuration and database files are stored as environment variables.
Environment Variable | Description |
---|---|
FTM_CONFIG_FILE_NAME | Absolute or relative path to the configuration file |
FTM_DATABASE_NAME | Absolute or relative path to the sqlite database |
Run Feed to Mastodon
To run Feed to Mastodon
via Docker, run the following command:
docker run -it --rm \
-v "${PWD}/ftm-feed-config.ini:/app/ftm-feed-config.ini" \
-v "${PWD}/ftm.sqlite:/app/ftm.sqlite" \
-e "FTM_CONFIG_FILE_NAME=/app/ftm-feed-config.ini" \
-e "FTM_DATABASE_NAME=/app/ftm.sqlite" \
davidullrich/feed-to-mastodon:latest
A Docker Compose configuration looks like this:
services:
ftm:
container_name: feed-to-mastodon
image: davidullrich/feed-to-mastodon:latest
restart: unless-stopped
volumes:
- ./data:/app/data
environment:
- FTM_DATABASE_NAME=/app/data/ftm.sqlite
- FTM_CONFIG_FILE_NAME=/app/data/ftm.ini
- TZ=Europe/Berlin
Statistics
For those interested, Feed to Mastodon
outputs a daily statistic on the console. This shows the number of feeds posted in the last 24 hours and the last seven days.
Statistics[0] ============================================================
Statistics[0] Total Posts per feed: 2024-11-18 00:00 - 2024-11-25 00:00
Statistics[0] ============================================================
Statistics[0] Mashable: 215
Statistics[0] Caschys Blog: 183
Statistics[0] Digital Trends: 299
Statistics[0] Elektroauto-News.net: 8
Statistics[0] TESLARATI: 48
Statistics[0] WIRED: 102
Statistics[0] ------------------------------------------------------------
Statistics[0] Total: 855
Statistics[0] ============================================================
Live example
At https://feedmirror.social, Feed to Mastodon
is running with a few configured feeds, bringing the latest articles into the Fediverse.