Added patch #1024088, better handling of various Ebay URLs.

This commit is contained in:
James Vega 2004-09-08 23:44:39 +00:00
parent ee70224aa3
commit ddfa5e8d32
2 changed files with 6 additions and 48 deletions

View File

@ -39,6 +39,7 @@ __revision__ = "$Id$"
__author__ = supybot.authors.jamessan __author__ = supybot.authors.jamessan
import re import re
import cgi
import sets import sets
import getopt import getopt
@ -117,10 +118,13 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp):
irc.reply(str(e)) irc.reply(str(e))
def ebaySnarfer(self, irc, msg, match): def ebaySnarfer(self, irc, msg, match):
r"http://cgi\.ebay\.(?:com(?:\.au)?|co\.uk|ca)/.*" \ r'http://cgi\.ebay\.(?:com(?:\.au)?|co\.uk|ca)/.*' \
r"eBayISAPI\.dll\?ViewItem(?:&(?:item|category)=\d+)+" r'eBayISAPI\.dll\?ViewItem&([\S]+)'
if not self.registryValue('auctionSnarfer', msg.args[0]): if not self.registryValue('auctionSnarfer', msg.args[0]):
return return
queries = cgi.parse_qs(match.group(1))
if 'item' not in queries and 'category' not in queries:
return
url = match.group(0) url = match.group(0)
try: try:
irc.reply(self._getResponse(url), prefixName=False) irc.reply(self._getResponse(url), prefixName=False)

View File

@ -40,50 +40,4 @@ class EbayTest(ChannelPluginTestCase):
self.assertRegexp('auction 2357056673', 'That auction is invalid') self.assertRegexp('auction 2357056673', 'That auction is invalid')
self.assertError('auction foobar') self.assertError('auction foobar')
def testSnarfer(self):
orig = conf.supybot.plugins.Ebay.auctionSnarfer()
try:
conf.supybot.plugins.Ebay.auctionSnarfer.setValue(True)
self.assertSnarfRegexp(
'http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem'
'&category=176&item=3053767552',
r'.*Cisco NP-4T.*Serial Module.*US \$74\.95.*')
self.assertSnarfRegexp(
'http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&'
'category=28033&item=3053353651',
r'.*Cisco 2524 Router - NO RESERVE.*izontech \(.*')
# test snarfing other countries
self.assertSnarfRegexp(
'http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&'
'item=3636820075',
r'NEW 34" Itech 8.8 Profile')
self.assertSnarfRegexp(
'http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&'
'item=2355464443',
r'Any Clear Crazy')
self.assertSnarfRegexp(
'http://cgi.ebay.com.au/ws/eBayISAPI.dll?ViewItem&'
'item=2762983161&category=4607',
r'Apple Mac G4')
# test .com/.*/ws/eBat compatibility
self.assertSnarfRegexp(
'http://cgi.ebay.com/ebaymotors/ws/eBayISAPI.dll?'
'ViewItem&item=2439393310&category=33708',
r'88-89 CRX amber')
finally:
conf.supybot.plugins.Ebay.auctionSnarfer.setValue(orig)
def testConfigSnarfer(self):
try:
conf.supybot.plugins.Ebay.auctionSnarfer.setValue(False)
self.assertSnarfNoResponse(
'http://cgi.ebay.com/ebaymotors/ws/eBayISAPI.dll?'
'ViewItem&item=2439393310&category=33708')
conf.supybot.plugins.Ebay.auctionSnarfer.setValue(True)
self.assertSnarfNotError(
'http://cgi.ebay.com/ebaymotors/ws/eBayISAPI.dll?'
'ViewItem&item=2439393310&category=33708')
finally:
conf.supybot.plugins.Ebay.auctionSnarfer.setValue(False)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: