TootRSS - a utility to auto-post RSS feed items to Mastodon

As I mentioned in this post, I’ve essentially abandoned Twitter in favor of Mastodon (you can find me on Mastodon via the link over there –> ). Now that I’m getting more active there, I wanted a quick and easy way to post new items published here to my Mastodon account for broader distribution and visibility. My initial inspiration came from this Dr. Drang post. At the time I wasn’t thinking about anything more complex than a simple script, but as I dove into the Mastodon API and ways to retrieve RSS items I quickly decided to make a utility that would do what I wanted in an automatable and recoverable way.

The things I wanted to accomplish were (in no particular order):

  • Post links to new items published via RSS to my Mastodon account
  • Have a consistent post message when this occurs
  • Be able to post automatically, like through cron
  • Keep track of what’s been posted so that only new stuff generates a post
  • Be secure, e.g. not leak credentials

What I ended up creating is the TootRSS utility. I won’t go into deep details since those are all in the repo’s README already, but I’ll note a few aspects:

  • Uses a DynamoDB table to keep history of what RSS items have been posted
  • Auto-creates the DynamoDB table if it doesn’t already exist
  • Has a cache-only mode, useful to bootstrap an existing RSS feed with items that you don’t want to generate a flood of posts from
  • Encrypts the necessary AWS and Mastodon tokens with Fernet, allowing them to be safely stored in GitHub and/or on the system you run it from

TootRSS syntax:

./tootrss.py -h
usage: tootrss [-h] [-a] [-c] [-k FERNET_KEY] [-m] [-q] [-v]

A utility to toot rss posts to Mastodon

optional arguments:
  -h, --help            show this help message and exit
  -a, --ask_key         ask user to input the Fernet key
  -c, --cache           just build the feed cache, do not toot
  -k FERNET_KEY, --fernet_key FERNET_KEY
                        the Fernet key used to ecrypt tokens
  -m, --make_table      create the feed cache table if it does not exist
  -q, --quiet           suppress all progress messages
  -v, --verbose         provide additional progress messages

While I was working on this, I accidentally discovered that storing an active AWS IAM token in GitHub will automatically generate an incident against your AWS account, which restricts the exposed IAM token and requires response to clear. Nice to know that integration is there that will safeguard IAM-based access to your AWS account. Nice touch.

I’ve licensed the TootRSS utility codebase with the MIT License, meaning that it’s relatively open for re-use if anyone is interested. I spent way too much time on it, but once I started I had to keep working on it until it did everything I wanted and was as neat and tidy code-wise as I could make it. It could probably use some additional code comments here and there, but it’s not so complicated that anyone with a good understanding of Python couldn’t figure it out.

Comments


Copyright

CC BY-NC-ND 4.0