Creating a bot to scan RSS feeds and YouTube playlists, and post updated to a Telegram channel.
I want a place where I can view updates to a number of feeds of Medium articles and YouTube playlists about Flutter. An RSS reader would handle the RSS feeds well, but I wasn’t happy with the YouTube playlists. Plus I thought It would make an interesting Flutter app. After starting to use Telegram, I thought it would also work as a Telegram channel. The Flutter app remains a future project.
This article covers the basics of parsing an RSS feed and posting to a Telegram channel. I have taken the code and modified it to handle multiple RSS feeds.
The above code works well for most RSS feeds, but not for ones generated from YouTube playlists. The YouTube Data API returns playlist items in a paginated way, sorted by playlist order. It appears that the RSS feed of a channel or playlist returns only the first page of results. So there’s no guarantee of getting the entire playlist, or the most recent entries (depending on playlist sort order).
To get around this, I needed to handle YouTube playlist as a special case. Fortunately, YouTube provides an API to list the items in a playlist, including code samples. I found this difficult to work with, as it required oauth authorization, even for APIs that access only publicly available information, and the documentation for creating the appropriate oauth configuration was out of date (select “Other” from a list that no longer contains “Other”). Why does the Python code, both examples and libraries, require oauth, when the
curl example does not?
The Python-YouTube library is a much easier way to consume the YouTube API. This made my code much simpler, and easier.
Deploying the Bot
The bot is currently running as a systemd service on a Raspberry Pi. This tutorial covers setting up a systemd service.
I may, in the future, deploy it to a cloud service like AWS Lambda, or Google Cloud.
Try It Out
You can read, and subscribe to the Widget News Telegram Channel.