From b6e98a577f242d41941c070293a681750d46ad0d Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 22 Mar 2003 07:53:46 +0000 Subject: [PATCH] Added slashdot command (thanks, inkedmn!) --- plugins/Http.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/Http.py b/plugins/Http.py index c5246555e..5791af31d 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -32,9 +32,10 @@ from baseplugin import * import re +import time import urllib2 import threading -#import xml.dom.minidom +import xml.dom.minidom import debug import privmsgs @@ -209,4 +210,24 @@ class Http(callbacks.Privmsg): except urllib2.URLError: irc.error(msg, 'Couldn\'t open the search page.') + _slashdotTime = 0.0 + def slashdot(self, irc, msg, args): + "takes no arguments" + if time.time() - self._slashdotTime > 1800: + try: + fd = urllib2.urlopen('http://slashdot.org/slashdot.xml') + slashdotXml = fd.read() + fd.close() + dom = xml.dom.minidom.parseString(slashdotXml) + headlines = [] + for headline in dom.getElementsByTagName('title'): + headlines.append(str(headline.firstChild.data)) + self._slashdotResponse = ' :: '.join(headlines) + self._slashdotTime = time.time() + except urllib2.URLError, e: + irc.error(msg, str(e)) + return + irc.reply(msg, self._slashdotResponse) + + Class = Http