All pastes #165 Raw Edit

eabinga

public text v1 · immutable
#165 ·published 2004-05-23 04:46 UTC
rendered paste body
#!/usr/bin/env python

__module_name__ = "eBot"
__module_version__ = "1.0"
__module_description__ = "Freerepublic RSS to IRC proxy"

from feedparser import *
import xchat
import re

url = "http://www.freerepublic.com/focus/f-news/browse.rss"
channel = "#spare1"

r = re.compile("^.+/(\d+)/.+$")
top_article = 0
myhook = None

def stop_cb(word, word_eol, userdata):
	global myhook 
	if myhook is not None: 
		xchat.unhook(myhook) 
		myhook = None 
		print "eBot stopped." 


def eBot_cb(userdata):
	global top_article
	feed = parse(url)
	max_article = 0
	
	for item in feed["items"]:
		article = int(r.search(item["links"][0]["href"]).group(1))
		if article > top_article:
			xchat.command("msg %s %s" % (channel, item["title"].encode("latin-1")))
			#xchat.command("msg %s  " % (channel))
			#xchat.command("msg %s %s" % (channel, item["description"].encode("latin-1")))
			#xchat.command("msg %s  " % (channel))
			xchat.command("msg %s http://www.freerepublic.com/focus/f-news/%s/posts" % (channel, article))
			xchat.command("msg %s  " % (channel))
			#print article
			if article > max_article:
				max_article = article

	if max_article > top_article:
		top_article = max_article

	return 1

myhook = xchat.hook_timer(60000, eBot_cb) 
xchat.hook_command("STOPEBOT", stop_cb)