mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 22:24:20 +01:00
Snarfer cleanups and toggle tests
This commit is contained in:
parent
d74a59a2f5
commit
68d36db874
@ -85,38 +85,20 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
_info = re.compile(r'<title>eBay item (\d+) \([^)]+\) - ([^<]+)</title>',
|
_info = re.compile(r'<title>eBay item (\d+) \([^)]+\) - ([^<]+)</title>',
|
||||||
_reopts)
|
_reopts)
|
||||||
|
|
||||||
_bid = re.compile(r'Current bid:.+?<b>([^<]+?)<font', _reopts)
|
_bid = re.compile(r'Current (bid):.+?<b>([^<]+?)<font', _reopts)
|
||||||
_getBid = lambda self, s: '%s: %s' % (ircutils.bold('Bid'),
|
_winningBid = re.compile(r'(Winning bid|Sold for):.+?<b>([^<]+?)<font',
|
||||||
self._bid.search(s).group(1))
|
|
||||||
|
|
||||||
_winningBid = re.compile(r'(?:Winning bid|Sold for):.+?<b>([^<]+?)<font',
|
|
||||||
_reopts)
|
_reopts)
|
||||||
_getWinningbid = lambda self, s: '%s: %s' % (ircutils.bold('Winning bid'),
|
_time = re.compile(r'(Time left):.+?<b>([^<]+?)</b>', _reopts)
|
||||||
self._winningBid.search(s).group(1))
|
_bidder = re.compile(r'(High bidder):.+?<a href[^>]+>([^<]+)</a>.+?<a '\
|
||||||
|
|
||||||
_time = re.compile(r'Time left:.+?<b>([^<]+?)</b>', _reopts)
|
|
||||||
_getTime = lambda self, s: '%s: %s' % (ircutils.bold('Time left'),
|
|
||||||
self._time.search(s).group(1))
|
|
||||||
|
|
||||||
_bidder = re.compile(r'High bidder:.+?<a href[^>]+>([^<]+)</a>.+?<a '\
|
|
||||||
'href[^>]+>(\d+)</a>', _reopts)
|
'href[^>]+>(\d+)</a>', _reopts)
|
||||||
_getBidder = lambda self, s: '%s: %s (%s)' % (ircutils.bold('Bidder'),
|
_winningBidder = re.compile(r'(Winning bidder|Buyer):.+?<a href[^>]+>'\
|
||||||
self._bidder.search(s).group(1), self._bidder.search(s).group(2))
|
|
||||||
|
|
||||||
_winningBidder = re.compile(r'(?:Winning bidder|Buyer):.+?<a href[^>]+>'\
|
|
||||||
'([^<]+)</a>.+?<a href[^>]+>(\d+)</a>', _reopts)
|
'([^<]+)</a>.+?<a href[^>]+>(\d+)</a>', _reopts)
|
||||||
_getWinningbidder = lambda self, s: '%s: %s (%s)' % (ircutils.bold(
|
_buyNow = re.compile(r'alt="(Buy It Now)">.*?<b>([^<]+)</b>')
|
||||||
'Winning bidder'), self._winningBidder.search(s).group(1),
|
_seller = re.compile(r'(Seller information).+?<a href[^>]+>([^<]+)</a>'\
|
||||||
self._winningBidder.search(s).group(2))
|
|
||||||
|
|
||||||
_buyNow = re.compile(r'alt="Buy It Now">.*?<b>([^<]+)</b>')
|
|
||||||
_getBuynow = lambda self, s: '%s: %s' % (ircutils.bold('Buy It Now'),
|
|
||||||
self._buyNow.search(s).group(1))
|
|
||||||
|
|
||||||
_seller = re.compile(r'Seller information.+?<a href[^>]+>([^<]+)</a>'\
|
|
||||||
'.+ViewFeedback.+">(\d+)</a>', _reopts)
|
'.+ViewFeedback.+">(\d+)</a>', _reopts)
|
||||||
_getSeller = lambda self, s: '%s: %s (%s)' % (ircutils.bold('Seller'),
|
_searches = (_bid, _winningBid, _time, _bidder, _winningBidder, _buyNow,
|
||||||
self._seller.search(s).group(1), self._seller.search(s).group(2))
|
_seller)
|
||||||
|
_multiField = (_bidder, _winningBidder, _seller)
|
||||||
|
|
||||||
def ebay(self, irc, msg, args):
|
def ebay(self, irc, msg, args):
|
||||||
"""[--link] <item>
|
"""[--link] <item>
|
||||||
@ -143,33 +125,39 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
if not self.toggles.get('auction', channel=msg.args[0]):
|
if not self.toggles.get('auction', channel=msg.args[0]):
|
||||||
return
|
return
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
|
#debug.printf(url)
|
||||||
self._getResponse(irc, msg, url, snarf = True)
|
self._getResponse(irc, msg, url, snarf = True)
|
||||||
|
|
||||||
|
_bold = lambda self, m: (ircutils.bold(m[0]),) + m[1:]
|
||||||
def _getResponse(self, irc, msg, url, snarf = False):
|
def _getResponse(self, irc, msg, url, snarf = False):
|
||||||
fd = urllib2.urlopen(url)
|
fd = urllib2.urlopen(url)
|
||||||
s = fd.read()
|
s = fd.read()
|
||||||
fd.close()
|
fd.close()
|
||||||
searches = (self._getBid, self._getBuynow, self._getWinningbid,
|
resp = []
|
||||||
self._getTime, self._getBidder, self._getWinningbidder,
|
m = self._info.search(s)
|
||||||
self._getSeller)
|
if m:
|
||||||
try:
|
(num, desc) = m.groups()
|
||||||
(num, desc) = self._info.search(s).groups()
|
resp.append('%s%s: %s' % (ircutils.bold('Item #'), ircutils.bold(num),
|
||||||
resp = ['%s%s: %s' % (ircutils.bold('Item #'), ircutils.bold(num),
|
utils.htmlToText(desc)))
|
||||||
utils.htmlToText(desc))]
|
for r in self._searches:
|
||||||
for i in searches:
|
m = r.search(s)
|
||||||
try:
|
if m:
|
||||||
resp.append('%s' % i(s))
|
if r in self._multiField:
|
||||||
except AttributeError:
|
resp.append('%s: %s (%s)' % self._bold(m.groups()))
|
||||||
pass
|
else:
|
||||||
|
resp.append('%s: %s' % self._bold(m.groups()))
|
||||||
|
if resp:
|
||||||
if snarf:
|
if snarf:
|
||||||
irc.reply(msg, '%s' % '; '.join(resp), prefixName = False)
|
irc.reply(msg, '%s' % '; '.join(resp), prefixName = False)
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, '%s' % '; '.join(resp))
|
irc.reply(msg, '%s' % '; '.join(resp))
|
||||||
except AttributeError:
|
else:
|
||||||
irc.error(msg, 'That doesn\'t appear to be a proper eBay Auction '\
|
if snarf:
|
||||||
'page. (%s)' % conf.replyPossibleBug)
|
irc.error(msg, '%s doesn\'t appear to be a proper eBay '\
|
||||||
except Exception, e:
|
'Auction page. (%s)' % (url, conf.replyPossibleBug))
|
||||||
irc.error(msg, debug.exnToString(e))
|
else:
|
||||||
|
irc.error(msg, 'That doesn\'t appear to be a proper eBay '\
|
||||||
|
'Auction page. (%s)' % conf.replyPossibleBug)
|
||||||
|
|
||||||
Class = Ebay
|
Class = Ebay
|
||||||
|
|
||||||
|
@ -45,6 +45,11 @@ class EbayTest(PluginTestCase, PluginDocumentation):
|
|||||||
'category=28033&item=3053353651', '.*Cisco 2524 Router - NO '\
|
'category=28033&item=3053353651', '.*Cisco 2524 Router - NO '\
|
||||||
'RESERVE.*izontech \(.*')
|
'RESERVE.*izontech \(.*')
|
||||||
|
|
||||||
|
def testToggle(self):
|
||||||
|
self.assertHelp('ebay toggle')
|
||||||
|
self.assertRegexp('ebay toggle auction', '\(auction: (?:On|Off)\)')
|
||||||
|
self.assertRegexp('ebay toggle auction off', '\(auction: Off\)')
|
||||||
|
self.assertRegexp('ebay toggle auction off', '\(auction: Off\)')
|
||||||
|
self.assertRegexp('ebay toggle auction on', '\(auction: On\)')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user