From ed06656025eb9f1e6ae8ad7963f7447f37e5ac9b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 19 Apr 2003 22:16:57 +0000 Subject: [PATCH] Moved google groups snarfer to the Google module. --- plugins/Forums.py | 27 --------------------------- plugins/Google.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/plugins/Forums.py b/plugins/Forums.py index 829ef8d52..233a638f1 100644 --- a/plugins/Forums.py +++ b/plugins/Forums.py @@ -47,33 +47,6 @@ import callbacks class Forums(callbacks.PrivmsgRegexp): threaded = True - _ggThread = re.compile(r'
Subject: ([^<]+)
') - _ggGroup = re.compile(r'Newsgroups: ]+>([^<]+)') - def googlegroups(self, irc, msg, match): - r"http://groups.google.com/[^\s]+" - request = urllib2.Request(match.group(0), headers=\ - {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'}) - fd = urllib2.urlopen(request) - text = fd.read() - fd.close() - if match.group(0).find('&prev=/') >= 0: - path = re.search('view the ]+)>no',text) - url = 'http://groups.google.com' - request = urllib2.Request('%s%s' % (url,path.group(1)), - headers={'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5;' - 'Windows NT 4.0)'}) - fd = urllib2.urlopen(request) - text = fd.read() - fd.close() - mThread = self._ggThread.search(text) - mGroup = self._ggGroup.search(text) - if mThread and mGroup: - irc.queueMsg(ircmsgs.privmsg(ircutils.replyTo(msg), - 'Google Groups: %s, %s' % (mGroup.group(1), mThread.group(1)))) - else: - irc.queueMsg(ircmsgs.privmsg(msg.args[0], - 'That doesn\'t appear to be a proper Google Groups page.')) - _gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<") _gkRating = re.compile(r": (\d+)[^:]+:
(\d+)[^,]+, (\d+)[^,]+, (\d+)") _gkGameTitle = re.compile(r"

(.*?)\s* \s*\(started") diff --git a/plugins/Google.py b/plugins/Google.py index 0d2f669d1..19e1b9d58 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -35,9 +35,10 @@ Acceses Google for various things. from baseplugin import * +import re import time import getopt -import operator +import urllib2 import google @@ -171,6 +172,35 @@ class GooglePrivmsgRegexp(callbacks.PrivmsgRegexp): url = data.results[0].URL irc.queueMsg(ircmsgs.privmsg(ircutils.replyTo(msg), url)) + _ggThread = re.compile(r'
Subject: ([^<]+)
') + _ggGroup = re.compile(r'Newsgroups: ]+>([^<]+)
') + def googlegroups(self, irc, msg, match): + r"http://groups.google.com/[^\s]+" + request = urllib2.Request(match.group(0), headers=\ + {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'}) + fd = urllib2.urlopen(request) + text = fd.read() + fd.close() + if match.group(0).find('&prev=/') >= 0: + path = re.search('view the ]+)>no',text) + url = 'http://groups.google.com' + request = urllib2.Request('%s%s' % (url,path.group(1)), + headers={'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5;' + 'Windows NT 4.0)'}) + fd = urllib2.urlopen(request) + text = fd.read() + fd.close() + mThread = self._ggThread.search(text) + mGroup = self._ggGroup.search(text) + if mThread and mGroup: + irc.queueMsg(ircmsgs.privmsg(ircutils.replyTo(msg), + 'Google Groups: %s, %s' % (mGroup.group(1), mThread.group(1)))) + else: + irc.queueMsg(ircmsgs.privmsg(msg.args[0], + 'That doesn\'t appear to be a proper Google Groups page.')) + + + class Google(callbacks.Combine): classes = [GooglePrivmsg, GooglePrivmsgRegexp]