A python IRC bot for keeping up with arXiv (or any RSS feed)

After some internet searching, it wasn’t hard to find enough inputs to write a IRC bot using Python. I hardly know any Python, but the language being so simple, you could write code in it just right away. Needless to say, the best part was that there were libraries for both Feed Parsing (duh!) and for IRC clients. A simple one hour long digging through documentation resulted in the following put-them-together code:


  1. IRC b0t that keeps track of RSS feeds
  2. Licensed under the GNU General Public License v3
  3. Copyright (2009) by Akarsh Simha

import irclib
import feedparser
import os
import threading
import time

channel_list = [] # Put in a list of channels
feed_list = [ "http://arxiv.org/rss/hep-th", "http://arxiv.org/rss/cs", "http://arxiv.org/rss/math-ph", "http://rss.slashdot.org/Slashdot/slashdot"]
old_entries_file = os.environ.get("HOME") + "/.b0t/old-feed-entries"

irc = irclib.IRC()
server = irc.server()

server.connect( "irc.freenode.org", 6667, "" ) # TODO: Make this general

  1. server.privmsg( "NickServ", "identify " )

msgqueue = []

def feed_refresh():
FILE = open( old_entries_file, "r" )
filetext = FILE.read()
for feed in feed_list:
NextFeed = False
d = feedparser.parse( feed )
for entry in d.entries:
if entry.title in filetext:
NextFeed = True
FILE = open( old_entries_file, "a" )
FILE.write( entry.title + "\n" )
msgqueue.append( entry.title + " : " + entry.link )
if NextFeed:
t = threading.Timer( 900.0, feed_refresh ) # TODO: make this static

for channel in channel_list:
server.join( channel )


while 1:
while len(msgqueue) > 0:
msg = msgqueue.pop()
for channel in channel_list:
server.privmsg( channel, msg )
time.sleep(1) # TODO: Fix bad code
time.sleep(1) # So that we don't hog the CPU!

Forgive me for writing ugly code. I’m a newbie pythoner, and this is my first python script that actually does something useful.

On a side note, I attended a semi-classical concert by Anil Srinivasan (Piano), Unnikrishnan (Vocal), and B S Purushottaman (Kanjira), and it was one awesome experience. The auditorium (the Lady Andal School auditorium, where Margazhi Raagam was shot AFAIK) was simply superb. The ambience, and the stage lighting were amazing too. It was the confluence of the music of all three artistes, the auditorium and the lighting that created the paradise that we experienced.