RSS Feed Reader

For a long while I have wanted a bot to sit in irc channels spitting out updates on rss feeds. I Think I have finally found all the pieces I need to write a bot in the way I like.

I have written up a really simple IRC client on top of asyncio, but it needs much more testing than a day of dev. I want to have ssl running before I try and run the bot against anything.

The RSS code is much simplier:

import aiohttp
import asyncio
import async_timeout
import feedparser

import pprint

INTERVAL = 60

async def fetch(session, url):
    with async_timeout.timeout(10):
        async with session.get(url) as response:
            return await response.text()

async def fetchfeeds(loop, feedurls, ircsock):
    last_entry = None

    feeds = []

    for url in feedurls:
        feeds.append({'url':url, 'last':""})

    while True:
        for feed in feeds:
            async with aiohttp.ClientSession(loop=loop) as session:
                html = await fetch(session, feed['url'])
                rss = feedparser.parse(html)
                if feed['last']:
                    if feed['last']['title'] != rss['entries'][0]['title'] and feed['last']['link'] != rss['entries'][0]['link']:
                        print("new entry")
                        feed['last'] = rss['entries'][0]

                        print("MSG {}".format(feed['last']['title']))
                        print("MSG {}".format(feed['last']['link']))
                else:
                    feed['last'] = rss['entries'][0]

        await asyncio.sleep(INTERVAL)

loop = asyncio.get_event_loop()
loop.run_until_complete(fetchfeeds(loop, ['https://n-o-d-e.net/rss/rss.xml',
    "http://localhost:8000/rss.xml"], None))

This is really only a proof of concept, there needs to be much more error handling before I would expect this to run for long.


Reading: Nemesis Games

Aberdeen, Scotland: 0°C, Partly cloudy overnight.