RSS feeds aggregator in Telegram
For me, an RSS feed aggregator is the most convenient way to consume news.
When Google Reader shut down I switched to Feedly, then I tried self-hosted Selfoss, but eventually came up with something even simpler.
As my main IM app is Telegram I found it the best place to put RSS news. Especially because Telegram has links previews and search and anything could be either pinned or sent to Saved Messages or to anyone else.
This is how it looks in Telegram:

And the whole solution fits into 58 lines of code! You can find all the source code on my GitHub.
import feedparser
import telebot
import json
import traceback
from time import mktime
from datetime import datetime
import html
import os
config = "config.json"
processed_file = "processed"
processed_items = {}
processed_items_new = {}
with open(processed_file) as file:
for line in file:
processed_items[line.rstrip()] = True
data = json.load( open( config) )
token = os.getenv('TELEGRAM_BOT_TOKEN')
chat_id = os.getenv('TELEGRAM_CHAT_ID')
bot = telebot.TeleBot(token, parse_mode="MARKDOWN")
try:
for url in data:
print(url)
last_time = datetime.fromisoformat(data[url])
print("Last time {}".format(last_time))
try:
feed = feedparser.parse(url)
except Exception as e:
print("Error happened on parsing feed " + url, e)
bot.send_message(chat_id, "Failed to parse feed " + url + " " + e)
for e in feed.entries[::-1]:
e_time = datetime.fromtimestamp(mktime(e["published_parsed"]))
e_link = e["link"]
if e_time > last_time and not e_link in processed_items:
print("Sending post from {}".format(e_time))
msg_template = '*{title}* \n [LINK]({link})'
if 'comments' in e:
msg_template = msg_template + ' [COMMENTS]({comments})'
msg = msg_template.format(**e)
print(msg)
bot.send_message(chat_id, msg)
last_time = e_time
processed_items_new[e_link] = True
data[url] = "{}".format(last_time)
except Exception as e:
print("Error happened ", e)
traceback.print_exc()
finally:
json.dump(data, open( config, 'w' ))
with open(processed_file, "a") as file:
for link in processed_items_new:
file.write(link + '\n')These env variables have to be provided:
- TELEGRAM_BOT_TOKEN - your Telegram bot token. You can create your bot with BotFather
- TELEGRAM_CHAT_ID - Telegram chat ID to send news to
All feeds are defined in config.json where the key is an RSS feed URL and the value is the last update time:
{
"https://www.lazurkin.de/feed.xml": "2025-01-26 14:17:29",
...
}processed file contains all URLs of processed articles to eliminate duplications, because some news sites republish the same article after fixing the title.
And everything is executed with crontab on my VPS:
*/10 7-22 * * * cd /home/vasa/rss2gram && export $(cat .env | xargs) && . .venv/bin/activate && python rss2gram.py > /home/vasa/rss2gram.log 2>&1
0 0 * * * sh -c ": > /home/vasa/rss2gram/processed"You can see that feeds are checked every 10 minutes from 7 till 22. Env variables are loaded from .env file.
processed file is cleaned up at midnight.
I find it very simple and convenient!
But lately I started thinking about a more comprehensive solution. The problem is that there is too much news and not all of it is interesting to me. If I skip one day of scrolling through news there will be hundreds of those in my inbox. So soon I will look into building a summarized and categorized daily news digest.
Stay tuned!