mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
I have the *power*! ... of webutils
This commit is contained in:
parent
1fa9e8c4a8
commit
9fe682fe29
@ -35,8 +35,6 @@ Accesses Sourceforge.net for various things
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import sets
|
import sets
|
||||||
import socket
|
|
||||||
import urllib2
|
|
||||||
|
|
||||||
from itertools import ifilter, imap
|
from itertools import ifilter, imap
|
||||||
|
|
||||||
@ -47,6 +45,7 @@ __revision__ = "$Id$"
|
|||||||
import plugins
|
import plugins
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
|
import webutils
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
|
|
||||||
@ -148,23 +147,19 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
|
|
||||||
def _getTrackerURL(self, project, regex):
|
def _getTrackerURL(self, project, regex):
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen('%s%s' % (self._projectURL, project))
|
text = webutils.getUrl('%s%s' % (self._projectURL, project))
|
||||||
text = fd.read()
|
|
||||||
fd.close()
|
|
||||||
m = regex.search(text)
|
m = regex.search(text)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise TrackerError, 'Invalid Tracker page'
|
raise TrackerError, 'Invalid Tracker page'
|
||||||
else:
|
else:
|
||||||
return 'http://sourceforge.net%s%s' % (utils.htmlToText(
|
return 'http://sourceforge.net%s%s' % (utils.htmlToText(
|
||||||
m.group(1)), self._hrefOpts)
|
m.group(1)), self._hrefOpts)
|
||||||
except urllib2.HTTPError, e:
|
except webutils.WebException, e:
|
||||||
raise callbacks.Error, str(e)
|
raise callbacks.Error, str(e)
|
||||||
|
|
||||||
def _getTrackerList(self, url):
|
def _getTrackerList(self, url):
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen(url)
|
text = webutils.getUrl(url)
|
||||||
text = fd.read()
|
|
||||||
fd.close()
|
|
||||||
head = '#%s: %s'
|
head = '#%s: %s'
|
||||||
resp = [head % entry for entry in self._formatResp(text)]
|
resp = [head % entry for entry in self._formatResp(text)]
|
||||||
if resp:
|
if resp:
|
||||||
@ -173,14 +168,12 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
return '%s' % utils.commaAndify(resp)
|
return '%s' % utils.commaAndify(resp)
|
||||||
raise callbacks.Error, 'No Trackers were found. (%s)' %\
|
raise callbacks.Error, 'No Trackers were found. (%s)' %\
|
||||||
conf.replyPossibleBug
|
conf.replyPossibleBug
|
||||||
except urllib2.HTTPError, e:
|
except webutils.WebException, e:
|
||||||
raise callbacks.Error, e.msg()
|
raise callbacks.Error, e.msg()
|
||||||
|
|
||||||
def _getTrackerInfo(self, irc, msg, url, num):
|
def _getTrackerInfo(self, irc, msg, url, num):
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen(url)
|
text = webutils.getUrl(url)
|
||||||
text = fd.read()
|
|
||||||
fd.close()
|
|
||||||
head = '%s <http://sourceforge.net%s>'
|
head = '%s <http://sourceforge.net%s>'
|
||||||
resp = [head % match for match in self._formatResp(text,num)]
|
resp = [head % match for match in self._formatResp(text,num)]
|
||||||
if resp:
|
if resp:
|
||||||
@ -188,7 +181,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
return
|
return
|
||||||
irc.error(msg, 'No Trackers were found. (%s)' %
|
irc.error(msg, 'No Trackers were found. (%s)' %
|
||||||
conf.replyPossibleBug)
|
conf.replyPossibleBug)
|
||||||
except urllib2.HTTPError, e:
|
except webutils.WebException, e:
|
||||||
irc.error(msg, e.msg())
|
irc.error(msg, e.msg())
|
||||||
|
|
||||||
_bugLink = re.compile(r'"([^"]+)">Bugs')
|
_bugLink = re.compile(r'"([^"]+)">Bugs')
|
||||||
@ -303,9 +296,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
fd = urllib2.urlopen(url)
|
s = webutils.getUrl(url)
|
||||||
s = fd.read()
|
|
||||||
fd.close()
|
|
||||||
resp = []
|
resp = []
|
||||||
head = ''
|
head = ''
|
||||||
m = self._linkType.search(s)
|
m = self._linkType.search(s)
|
||||||
@ -326,7 +317,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
resp.append('%s: %s' % self._bold(m.groups()))
|
resp.append('%s: %s' % self._bold(m.groups()))
|
||||||
irc.reply(msg, '%s #%s: %s' % (ircutils.bold(linktype),
|
irc.reply(msg, '%s #%s: %s' % (ircutils.bold(linktype),
|
||||||
ircutils.bold(num), '; '.join(resp)), prefixName = False)
|
ircutils.bold(num), '; '.join(resp)), prefixName = False)
|
||||||
except (urllib2.HTTPError, socket.error), e:
|
except webutils.WebException, e:
|
||||||
self.log.warning(str(e))
|
self.log.warning(str(e))
|
||||||
sfSnarfer = privmsgs.urlSnarfer(sfSnarfer)
|
sfSnarfer = privmsgs.urlSnarfer(sfSnarfer)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user