mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added amazon snarfer and price information.
This commit is contained in:
parent
7192e97376
commit
3851d1d152
@ -77,13 +77,18 @@ conf.registerGlobalValue(conf.supybot.plugins.Amazon, 'licenseKey',
|
|||||||
LicenseKey('', """Sets the license key for using Amazon Web Services.
|
LicenseKey('', """Sets the license key for using Amazon Web Services.
|
||||||
Must be set before any other commands in the plugin are used.""",
|
Must be set before any other commands in the plugin are used.""",
|
||||||
private=True))
|
private=True))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Amazon, 'linkSnarfer',
|
||||||
|
registry.Boolean(False, """Determines whether the bot will reply to
|
||||||
|
Amazon.com URLs in the channel with a description of the item at the
|
||||||
|
URL."""))
|
||||||
|
|
||||||
class Amazon(callbacks.Privmsg):
|
class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
threaded = True
|
threaded = True
|
||||||
|
regexps = ['amzSnarfer']
|
||||||
|
|
||||||
def callCommand(self, method, irc, msg, *L):
|
def callCommand(self, method, irc, msg, *L, **kwargs):
|
||||||
try:
|
try:
|
||||||
callbacks.Privmsg.callCommand(self, method, irc, msg, *L)
|
callbacks.PrivmsgCommandAndRegexp.callCommand(self, method, irc, msg, *L, **kwargs)
|
||||||
except amazon.NoLicenseKey, e:
|
except amazon.NoLicenseKey, e:
|
||||||
irc.error('You must have a free Amazon web services license key '
|
irc.error('You must have a free Amazon web services license key '
|
||||||
'in order to use this command. You can get one at '
|
'in order to use this command. You can get one at '
|
||||||
@ -138,10 +143,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
attribs = {'ProductName' : 'title',
|
attribs = {'ProductName' : 'title',
|
||||||
'Manufacturer' : 'publisher',
|
'Manufacturer' : 'publisher',
|
||||||
'Authors' : 'author',
|
'Authors' : 'author',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s", written by %(author)s; published by ' \
|
s = '"%(title)s", written by %(author)s; published by ' \
|
||||||
'%(publisher)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
book = amazon.searchByKeyword(isbn)
|
book = amazon.searchByKeyword(isbn)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -171,10 +177,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
attribs = {'ProductName' : 'title',
|
attribs = {'ProductName' : 'title',
|
||||||
'Manufacturer' : 'publisher',
|
'Manufacturer' : 'publisher',
|
||||||
'Authors' : 'author',
|
'Authors' : 'author',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s", written by %(author)s; published by ' \
|
s = '"%(title)s", written by %(author)s; published by ' \
|
||||||
'%(publisher)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
books = amazon.searchByKeyword(keyword)
|
books = amazon.searchByKeyword(keyword)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -210,10 +217,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
'MpaaRating' : 'mpaa',
|
'MpaaRating' : 'mpaa',
|
||||||
'Media' : 'media',
|
'Media' : 'media',
|
||||||
'ReleaseDate' : 'date',
|
'ReleaseDate' : 'date',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released ' \
|
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released ' \
|
||||||
'%(date)s; published by %(publisher)s%(url)s'
|
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
videos = amazon.searchByKeyword(keyword, product_line=product)
|
videos = amazon.searchByKeyword(keyword, product_line=product)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -242,9 +250,10 @@ class Amazon(callbacks.Privmsg):
|
|||||||
asin = privmsgs.getArgs(rest)
|
asin = privmsgs.getArgs(rest)
|
||||||
asin = asin.replace('-', '').replace(' ', '')
|
asin = asin.replace('-', '').replace(' ', '')
|
||||||
attribs = {'ProductName' : 'title',
|
attribs = {'ProductName' : 'title',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s"%(url)s'
|
s = '"%(title)s"; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByASIN(asin)
|
item = amazon.searchByASIN(asin)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -276,9 +285,10 @@ class Amazon(callbacks.Privmsg):
|
|||||||
upc = upc.replace('-', '').replace(' ', '')
|
upc = upc.replace('-', '').replace(' ', '')
|
||||||
attribs = {'ProductName' : 'title',
|
attribs = {'ProductName' : 'title',
|
||||||
'Manufacturer' : 'manufacturer',
|
'Manufacturer' : 'manufacturer',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s" %(manufacturer)s%(url)s'
|
s = '"%(title)s" %(manufacturer)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByUPC(upc)
|
item = amazon.searchByUPC(upc)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -308,10 +318,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
attribs = {'ProductName' : 'title',
|
attribs = {'ProductName' : 'title',
|
||||||
'Manufacturer' : 'publisher',
|
'Manufacturer' : 'publisher',
|
||||||
'Authors' : 'author',
|
'Authors' : 'author',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s", written by %(author)s; published by ' \
|
s = '"%(title)s", written by %(author)s; published by ' \
|
||||||
'%(publisher)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
books = amazon.searchByAuthor(author)
|
books = amazon.searchByAuthor(author)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -406,10 +417,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
'Manufacturer' : 'publisher',
|
'Manufacturer' : 'publisher',
|
||||||
'Artists' : 'artist',
|
'Artists' : 'artist',
|
||||||
'Media' : 'media',
|
'Media' : 'media',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s" (%(media)s), by %(artist)s; published by ' \
|
s = '"%(title)s" (%(media)s), by %(artist)s; published by ' \
|
||||||
'%(publisher)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByArtist(artist, product_line=product)
|
items = amazon.searchByArtist(artist, product_line=product)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -446,10 +458,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
'MpaaRating' : 'mpaa',
|
'MpaaRating' : 'mpaa',
|
||||||
'Media' : 'media',
|
'Media' : 'media',
|
||||||
'ReleaseDate' : 'date',
|
'ReleaseDate' : 'date',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released ' \
|
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released ' \
|
||||||
'%(date)s; published by %(publisher)s%(url)s'
|
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByActor(actor, product_line=product)
|
items = amazon.searchByActor(actor, product_line=product)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -486,10 +499,11 @@ class Amazon(callbacks.Privmsg):
|
|||||||
'MpaaRating' : 'mpaa',
|
'MpaaRating' : 'mpaa',
|
||||||
'Media' : 'media',
|
'Media' : 'media',
|
||||||
'ReleaseDate' : 'date',
|
'ReleaseDate' : 'date',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released ' \
|
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released ' \
|
||||||
'%(date)s; published by %(publisher)s%(url)s'
|
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByDirector(director, product_line=product)
|
items = amazon.searchByDirector(director, product_line=product)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
@ -525,9 +539,10 @@ class Amazon(callbacks.Privmsg):
|
|||||||
product = product or 'pc-hardware'
|
product = product or 'pc-hardware'
|
||||||
manufacturer = privmsgs.getArgs(rest)
|
manufacturer = privmsgs.getArgs(rest)
|
||||||
attribs = {'ProductName' : 'title',
|
attribs = {'ProductName' : 'title',
|
||||||
|
'OurPrice' : 'price',
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '"%(title)s"%(url)s'
|
s = '"%(title)s"; price: %(price)s%(url)s'
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByManufacturer(manufacturer,
|
items = amazon.searchByManufacturer(manufacturer,
|
||||||
product_line=product)
|
product_line=product)
|
||||||
@ -540,6 +555,39 @@ class Amazon(callbacks.Privmsg):
|
|||||||
pass
|
pass
|
||||||
irc.error('No items were found by that manufacturer.')
|
irc.error('No items were found by that manufacturer.')
|
||||||
|
|
||||||
|
def amzSnarfer(self, irc, msg, match):
|
||||||
|
r"http://www.amazon.com/exec/obidos/(?:tg/detail/-/|ASIN/)([^/]+)"
|
||||||
|
if not self.registryValue('linkSnarfer', msg.args[0]):
|
||||||
|
return
|
||||||
|
match = match.group(1)
|
||||||
|
# attribs is limited to ProductName since the URL can link to
|
||||||
|
# *any* type of product. The only attribute we know it will have
|
||||||
|
# is ProductName
|
||||||
|
attribs = {'ProductName' : 'title',
|
||||||
|
'Manufacturer' : 'publisher',
|
||||||
|
'Authors' : 'author',
|
||||||
|
'MpaaRating' : 'mpaa',
|
||||||
|
'Media' : 'media',
|
||||||
|
'ReleaseDate' : 'date',
|
||||||
|
'OurPrice' : 'price',
|
||||||
|
'Artists' : 'artist',
|
||||||
|
}
|
||||||
|
s = '"%(title)s"; %(artist)s; %(author)s; %(mpaa)s; %(media)s; '\
|
||||||
|
'%(date)s; %(publisher)s; price: %(price)s'
|
||||||
|
try:
|
||||||
|
item = amazon.searchByASIN(match)
|
||||||
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
|
res = self._genResults(s, attribs, item, False, bold, 'title')
|
||||||
|
if res:
|
||||||
|
res = utils.commaAndify(res)
|
||||||
|
res = res.replace('; unknown', '')
|
||||||
|
res = res.replace('; price: unknown', '')
|
||||||
|
irc.reply(res, prefixName=False)
|
||||||
|
return
|
||||||
|
except amazon.AmazonError, e:
|
||||||
|
pass
|
||||||
|
self.log.warning('No item was found with that ASIN.')
|
||||||
|
|
||||||
Class = Amazon
|
Class = Amazon
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -109,5 +109,21 @@ if LICENSE_KEY != 'INITIAL_NON_LICENSE_KEY' and network:
|
|||||||
self.assertRegexp('videos zim', r'Demystifying the Devil.*DVD')
|
self.assertRegexp('videos zim', r'Demystifying the Devil.*DVD')
|
||||||
self.assertRegexp('videos --vhs samuel jackson', r'VHS Tape')
|
self.assertRegexp('videos --vhs samuel jackson', r'VHS Tape')
|
||||||
|
|
||||||
|
def testSnarfer(self):
|
||||||
|
try:
|
||||||
|
orig = conf.supybot.plugins.Amazon.linkSnarfer()
|
||||||
|
conf.supybot.plugins.Amazon.linkSnarfer.setValue(True)
|
||||||
|
self.assertRegexp('http://www.amazon.com/exec/obidos/tg/'
|
||||||
|
'detail/-/B0001CSI3S/sr=1-2/qid=1076951698'
|
||||||
|
'/ref=sr_1_2/002-0542016-6528044?v=glance&'
|
||||||
|
'n=1044448&s=apparel',
|
||||||
|
r'.*Spring Parka.*')
|
||||||
|
finally:
|
||||||
|
conf.supybot.plugins.Amazon.linkSnarfer.setValue(orig)
|
||||||
|
self.assertNoResponse('http://www.amazon.com/exec/obidos/tg/detail'
|
||||||
|
'/-/B0001CSI3S/sr=1-2/qid=1076951698/ref='
|
||||||
|
'sr_1_2/002-0542016-6528044?v=glance&n='
|
||||||
|
'1044448&s=apparel')
|
||||||
|
|
||||||
# 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