mirror of https://github.com/Mikaela/Limnoria.git
Update others/amazon.py to latest version and add the new region support to
plugins/Amazon.py (supybot.plugins.Amazon.region)
This commit is contained in:
parent
b70a683df1
commit
b9db0330e4
131
others/amazon.py
131
others/amazon.py
|
@ -54,15 +54,26 @@ Other usage notes:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Mark Pilgrim (f8dy@diveintomark.org)"
|
__author__ = "Mark Pilgrim (f8dy@diveintomark.org)"
|
||||||
__version__ = "0.61"
|
__version__ = "0.64.1"
|
||||||
__cvsversion__ = "$Revision$"[11:-2]
|
__cvsversion__ = "$Revision$"[11:-2]
|
||||||
__date__ = "$Date$"[7:-2]
|
__date__ = "$Date$"[7:-2]
|
||||||
__copyright__ = "Copyright (c) 2002 Mark Pilgrim"
|
__copyright__ = "Copyright (c) 2002 Mark Pilgrim"
|
||||||
__license__ = "Python"
|
__license__ = "Python"
|
||||||
# Powersearch and return object type fix by Joseph Reagle <geek@goatee.net>
|
# Powersearch and return object type fix by Joseph Reagle <geek@goatee.net>
|
||||||
|
|
||||||
|
# Locale support by Michael Josephson <mike@josephson.org>
|
||||||
|
|
||||||
|
# Modification to _contentsOf to strip trailing whitespace when loading Amazon key
|
||||||
|
# from a file submitted by Patrick Phalen.
|
||||||
|
|
||||||
|
# Support for specifying locale and associates ID as search parameters and
|
||||||
|
# internationalisation fix for the SalesRank integer conversion by
|
||||||
|
# Christian Theune <ct@gocept.com>, gocept gmbh & co. kg
|
||||||
|
|
||||||
|
# Support for BlendedSearch contributed by Alex Choo
|
||||||
|
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
import os, sys, getopt, cgi, urllib
|
import os, sys, getopt, cgi, urllib, string
|
||||||
try:
|
try:
|
||||||
import timeoutsocket # http://www.timo-tasi.org/python/timeoutsocket.py
|
import timeoutsocket # http://www.timo-tasi.org/python/timeoutsocket.py
|
||||||
timeoutsocket.setDefaultSocketTimeout(10)
|
timeoutsocket.setDefaultSocketTimeout(10)
|
||||||
|
@ -70,7 +81,9 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
LICENSE_KEY = None
|
LICENSE_KEY = None
|
||||||
|
ASSOCIATE = "webservices-20"
|
||||||
HTTP_PROXY = None
|
HTTP_PROXY = None
|
||||||
|
LOCALE = "us"
|
||||||
|
|
||||||
# don't touch the rest of these constants
|
# don't touch the rest of these constants
|
||||||
class AmazonError(Exception): pass
|
class AmazonError(Exception): pass
|
||||||
|
@ -88,6 +101,12 @@ _licenseLocations = (
|
||||||
(lambda key: _contentsOf(_getScriptDir(), _amazonfile1), '%s in the amazon.py directory' % _amazonfile1),
|
(lambda key: _contentsOf(_getScriptDir(), _amazonfile1), '%s in the amazon.py directory' % _amazonfile1),
|
||||||
(lambda key: _contentsOf(_getScriptDir(), _amazonfile2), '%s in the amazon.py directory' % _amazonfile2)
|
(lambda key: _contentsOf(_getScriptDir(), _amazonfile2), '%s in the amazon.py directory' % _amazonfile2)
|
||||||
)
|
)
|
||||||
|
_supportedLocales = {
|
||||||
|
"us" : (None, "xml.amazon.com"),
|
||||||
|
"uk" : ("uk", "xml-eu.amazon.com"),
|
||||||
|
"de" : ("de", "xml-eu.amazon.com"),
|
||||||
|
"jp" : ("jp", "xml.amazon.co.jp")
|
||||||
|
}
|
||||||
|
|
||||||
## administrative functions
|
## administrative functions
|
||||||
def version():
|
def version():
|
||||||
|
@ -96,7 +115,30 @@ def version():
|
||||||
released %(__date__)s
|
released %(__date__)s
|
||||||
""" % globals()
|
""" % globals()
|
||||||
|
|
||||||
|
def setAssociate(associate):
|
||||||
|
global ASSOCIATE
|
||||||
|
ASSOCIATE=associate
|
||||||
|
|
||||||
|
def getAssociate(override=None):
|
||||||
|
return override or ASSOCIATE
|
||||||
|
|
||||||
## utility functions
|
## utility functions
|
||||||
|
|
||||||
|
def _checkLocaleSupported(locale):
|
||||||
|
if not _supportedLocales.has_key(locale):
|
||||||
|
raise AmazonError, ("Unsupported locale. Locale must be one of: %s" %
|
||||||
|
string.join(_supportedLocales, ", "))
|
||||||
|
|
||||||
|
def setLocale(locale):
|
||||||
|
"""set locale"""
|
||||||
|
global LOCALE
|
||||||
|
_checkLocaleSupported(locale)
|
||||||
|
LOCALE = locale
|
||||||
|
|
||||||
|
def getLocale(locale=None):
|
||||||
|
"""get locale"""
|
||||||
|
return locale or LOCALE
|
||||||
|
|
||||||
def setLicense(license_key):
|
def setLicense(license_key):
|
||||||
"""set license key"""
|
"""set license key"""
|
||||||
global LICENSE_KEY
|
global LICENSE_KEY
|
||||||
|
@ -133,7 +175,7 @@ def _contentsOf(dirname, filename):
|
||||||
filename = os.path.join(dirname, filename)
|
filename = os.path.join(dirname, filename)
|
||||||
if not os.path.exists(filename): return None
|
if not os.path.exists(filename): return None
|
||||||
fsock = open(filename)
|
fsock = open(filename)
|
||||||
contents = fsock.read()
|
contents = fsock.read().strip()
|
||||||
fsock.close()
|
fsock.close()
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
|
@ -170,13 +212,19 @@ def unmarshal(element):
|
||||||
else:
|
else:
|
||||||
rc = "".join([e.data for e in element.childNodes if isinstance(e, minidom.Text)])
|
rc = "".join([e.data for e in element.childNodes if isinstance(e, minidom.Text)])
|
||||||
if element.tagName == 'SalesRank':
|
if element.tagName == 'SalesRank':
|
||||||
rc = int(rc.replace(',', ''))
|
rc = rc.replace('.', '')
|
||||||
|
rc = rc.replace(',', '')
|
||||||
|
rc = int(rc)
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
def buildURL(search_type, keyword, product_line, type, page, license_key):
|
def buildURL(search_type, keyword, product_line, type, page, license_key, locale, associate):
|
||||||
url = "http://xml.amazon.com/onca/xml3?v=2.0&f=xml&t=webservices-20"
|
_checkLocaleSupported(locale)
|
||||||
|
url = "http://" + _supportedLocales[locale][1] + "/onca/xml3?f=xml"
|
||||||
|
url += "&t=%s" % associate
|
||||||
url += "&dev-t=%s" % license_key.strip()
|
url += "&dev-t=%s" % license_key.strip()
|
||||||
url += "&type=%s" % type
|
url += "&type=%s" % type
|
||||||
|
if _supportedLocales[locale][0]:
|
||||||
|
url += "&locale=%s" % _supportedLocales[locale][0]
|
||||||
if page:
|
if page:
|
||||||
url += "&page=%s" % page
|
url += "&page=%s" % page
|
||||||
if product_line:
|
if product_line:
|
||||||
|
@ -189,7 +237,7 @@ def buildURL(search_type, keyword, product_line, type, page, license_key):
|
||||||
|
|
||||||
|
|
||||||
def search(search_type, keyword, product_line, type = "heavy", page = None,
|
def search(search_type, keyword, product_line, type = "heavy", page = None,
|
||||||
license_key = None, http_proxy = None):
|
license_key=None, http_proxy = None, locale = None, associate = None):
|
||||||
"""search Amazon
|
"""search Amazon
|
||||||
|
|
||||||
You need a license key to call this function; see
|
You need a license key to call this function; see
|
||||||
|
@ -235,7 +283,10 @@ def search(search_type, keyword, product_line, type="heavy", page=None,
|
||||||
URL - URL of this item
|
URL - URL of this item
|
||||||
"""
|
"""
|
||||||
license_key = getLicense(license_key)
|
license_key = getLicense(license_key)
|
||||||
url = buildURL(search_type, keyword, product_line, type, page, license_key)
|
locale = getLocale(locale)
|
||||||
|
associate = getAssociate(associate)
|
||||||
|
url = buildURL(search_type, keyword, product_line, type, page,
|
||||||
|
license_key, locale, associate)
|
||||||
proxies = getProxies(http_proxy)
|
proxies = getProxies(http_proxy)
|
||||||
u = urllib.FancyURLopener(proxies)
|
u = urllib.FancyURLopener(proxies)
|
||||||
usock = u.open(url)
|
usock = u.open(url)
|
||||||
|
@ -245,57 +296,69 @@ def search(search_type, keyword, product_line, type="heavy", page=None,
|
||||||
# PrettyPrint(xmldoc)
|
# PrettyPrint(xmldoc)
|
||||||
|
|
||||||
usock.close()
|
usock.close()
|
||||||
|
if search_type == "BlendedSearch":
|
||||||
|
data = unmarshal(xmldoc).BlendedSearch
|
||||||
|
else:
|
||||||
data = unmarshal(xmldoc).ProductInfo
|
data = unmarshal(xmldoc).ProductInfo
|
||||||
|
|
||||||
if hasattr(data, 'ErrorMsg'):
|
if hasattr(data, 'ErrorMsg'):
|
||||||
raise AmazonError, data.ErrorMsg
|
raise AmazonError, data.ErrorMsg
|
||||||
|
else:
|
||||||
|
if search_type == "BlendedSearch":
|
||||||
|
# a list of ProductLine containing a list of ProductInfo
|
||||||
|
# containing a list of Details.
|
||||||
|
return data
|
||||||
else:
|
else:
|
||||||
return data.Details
|
return data.Details
|
||||||
|
|
||||||
def searchByKeyword(keyword, product_line="books", type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByKeyword(keyword, product_line="books", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("KeywordSearch", keyword, product_line, type, page, license_key, http_proxy)
|
return search("KeywordSearch", keyword, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def browseBestSellers(browse_node, product_line="books", type="heavy", page=1, license_key=None, http_proxy=None):
|
def browseBestSellers(browse_node, product_line="books", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("BrowseNodeSearch", browse_node, product_line, type, page, license_key, http_proxy)
|
return search("BrowseNodeSearch", browse_node, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByASIN(ASIN, type="heavy", license_key=None, http_proxy=None):
|
def searchByASIN(ASIN, type="heavy", license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("AsinSearch", ASIN, None, type, None, license_key, http_proxy)
|
return search("AsinSearch", ASIN, None, type, None, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByUPC(UPC, type="heavy", license_key=None, http_proxy=None):
|
def searchByUPC(UPC, type="heavy", license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("UpcSearch", UPC, None, type, None, license_key, http_proxy)
|
return search("UpcSearch", UPC, None, type, None, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByAuthor(author, type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByAuthor(author, type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("AuthorSearch", author, "books", type, page, license_key, http_proxy)
|
return search("AuthorSearch", author, "books", type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByArtist(artist, product_line="music", type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByArtist(artist, product_line="music", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
if product_line not in ("music", "classical"):
|
if product_line not in ("music", "classical"):
|
||||||
raise AmazonError, "product_line must be in ('music', 'classical')"
|
raise AmazonError, "product_line must be in ('music', 'classical')"
|
||||||
return search("ArtistSearch", artist, product_line, type, page, license_key, http_proxy)
|
return search("ArtistSearch", artist, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByActor(actor, product_line="dvd", type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByActor(actor, product_line="dvd", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
if product_line not in ("dvd", "vhs", "video"):
|
if product_line not in ("dvd", "vhs", "video"):
|
||||||
raise AmazonError, "product_line must be in ('dvd', 'vhs', 'video')"
|
raise AmazonError, "product_line must be in ('dvd', 'vhs', 'video')"
|
||||||
return search("ActorSearch", actor, product_line, type, page, license_key, http_proxy)
|
return search("ActorSearch", actor, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByDirector(director, product_line="dvd", type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByDirector(director, product_line="dvd", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
if product_line not in ("dvd", "vhs", "video"):
|
if product_line not in ("dvd", "vhs", "video"):
|
||||||
raise AmazonError, "product_line must be in ('dvd', 'vhs', 'video')"
|
raise AmazonError, "product_line must be in ('dvd', 'vhs', 'video')"
|
||||||
return search("DirectorSearch", director, product_line, type, page, license_key, http_proxy)
|
return search("DirectorSearch", director, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByManufacturer(manufacturer, product_line="pc-hardware", type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByManufacturer(manufacturer, product_line="pc-hardware", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
if product_line not in ("electronics", "kitchen", "videogames", "software", "photo", "pc-hardware"):
|
if product_line not in ("electronics", "kitchen", "videogames", "software", "photo", "pc-hardware"):
|
||||||
raise AmazonError, "product_line must be in ('electronics', 'kitchen', 'videogames', 'software', 'photo', 'pc-hardware')"
|
raise AmazonError, "product_line must be in ('electronics', 'kitchen', 'videogames', 'software', 'photo', 'pc-hardware')"
|
||||||
return search("ManufacturerSearch", manufacturer, product_line, type, page, license_key, http_proxy)
|
return search("ManufacturerSearch", manufacturer, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByListMania(listManiaID, type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByListMania(listManiaID, type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("ListManiaSearch", listManiaID, None, type, page, license_key, http_proxy)
|
return search("ListManiaSearch", listManiaID, None, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchSimilar(ASIN, type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchSimilar(ASIN, type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("SimilaritySearch", ASIN, None, type, page, license_key, http_proxy)
|
return search("SimilaritySearch", ASIN, None, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByWishlist(wishlistID, type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByWishlist(wishlistID, type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("WishlistSearch", wishlistID, None, type, page, license_key, http_proxy)
|
return search("WishlistSearch", wishlistID, None, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
||||||
def searchByPower(keyword, product_line="books", type="heavy", page=1, license_key=None, http_proxy=None):
|
def searchByPower(keyword, product_line="books", type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
return search("PowerSearch", keyword, product_line, type, page, license_key, http_proxy)
|
return search("PowerSearch", keyword, product_line, type, page, license_key, http_proxy, locale, associate)
|
||||||
# >>> RecentKing = amazon.searchByPower('author:Stephen King and pubdate:2003')
|
# >>> RecentKing = amazon.searchByPower('author:Stephen King and pubdate:2003')
|
||||||
# >>> SnowCrash = amazon.searchByPower('title:Snow Crash')
|
# >>> SnowCrash = amazon.searchByPower('title:Snow Crash')
|
||||||
|
|
||||||
|
def searchByBlended(keyword, type="heavy", page=1, license_key=None, http_proxy=None, locale=None, associate=None):
|
||||||
|
return search("BlendedSearch", keyword, None, type, page, license_key, http_proxy, locale, associate)
|
||||||
|
|
|
@ -63,6 +63,9 @@ def configure(advanced):
|
||||||
You can apply for a key at
|
You can apply for a key at
|
||||||
http://www.amazon.com/webservices/""")
|
http://www.amazon.com/webservices/""")
|
||||||
|
|
||||||
|
class Region(registry.OnlySomeStrings):
|
||||||
|
validStrings = ('us', 'uk', 'de', 'jp')
|
||||||
|
|
||||||
class LicenseKey(registry.String):
|
class LicenseKey(registry.String):
|
||||||
def set(self, s):
|
def set(self, s):
|
||||||
# In case we decide we need to recover
|
# In case we decide we need to recover
|
||||||
|
@ -82,14 +85,20 @@ conf.registerChannelValue(conf.supybot.plugins.Amazon, 'linkSnarfer',
|
||||||
registry.Boolean(False, """Determines whether the bot will reply to
|
registry.Boolean(False, """Determines whether the bot will reply to
|
||||||
Amazon.com URLs in the channel with a description of the item at the
|
Amazon.com URLs in the channel with a description of the item at the
|
||||||
URL."""))
|
URL."""))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Amazon, 'region', Region('us',
|
||||||
|
"""Determines the region that will be used when performing searches."""))
|
||||||
|
|
||||||
class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
threaded = True
|
threaded = True
|
||||||
callBefore = ['URL']
|
callBefore = ['URL']
|
||||||
regexps = ['amzSnarfer']
|
regexps = ['amzSnarfer']
|
||||||
|
def __init__(self):
|
||||||
|
self.__parent = super(Amazon, self)
|
||||||
|
self.__parent.__init__()
|
||||||
|
|
||||||
def callCommand(self, name, irc, msg, *L, **kwargs):
|
def callCommand(self, name, irc, msg, *L, **kwargs):
|
||||||
try:
|
try:
|
||||||
super(Amazon, self).callCommand(name, irc, msg, *L, **kwargs)
|
self.__parent.callCommand(name, 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 '
|
||||||
|
@ -153,9 +162,11 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s, written by %(author)s; published by ' \
|
s = '%(title)s, written by %(author)s; published by ' \
|
||||||
'%(publisher)s; price: %(price)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
try:
|
try:
|
||||||
book = amazon.searchByKeyword(isbn)
|
book = amazon.searchByKeyword(isbn, locale=region)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
|
||||||
res = self._genResults(s, attribs, book, url, bold, 'title')
|
res = self._genResults(s, attribs, book, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -187,9 +198,11 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s, written by %(author)s; published by ' \
|
s = '%(title)s, written by %(author)s; published by ' \
|
||||||
'%(publisher)s; price: %(price)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
books = amazon.searchByKeyword(keyword)
|
books = amazon.searchByKeyword(keyword, locale=region)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
|
||||||
res = self._genResults(s, attribs, books, url, bold, 'title')
|
res = self._genResults(s, attribs, books, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -227,9 +240,12 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \
|
s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \
|
||||||
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
videos = amazon.searchByKeyword(keyword, product_line=product)
|
videos = amazon.searchByKeyword(keyword, product_line=product,
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
locale=region)
|
||||||
res = self._genResults(s, attribs, videos, url, bold, 'title')
|
res = self._genResults(s, attribs, videos, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -259,9 +275,11 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '%(title)s; price: %(price)s%(url)s'
|
s = '%(title)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByASIN(asin)
|
item = amazon.searchByASIN(asin, locale=region)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
|
||||||
res = self._genResults(s, attribs, item, url, bold, 'title')
|
res = self._genResults(s, attribs, item, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -294,9 +312,11 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '%(title)s %(manufacturer)s; price: %(price)s%(url)s'
|
s = '%(title)s %(manufacturer)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByUPC(upc)
|
item = amazon.searchByUPC(upc, locale=region)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
|
||||||
res = self._genResults(s, attribs, item, url, bold, 'title')
|
res = self._genResults(s, attribs, item, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -328,9 +348,11 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s, written by %(author)s; published by ' \
|
s = '%(title)s, written by %(author)s; published by ' \
|
||||||
'%(publisher)s; price: %(price)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
books = amazon.searchByAuthor(author)
|
books = amazon.searchByAuthor(author, locale=region)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
|
||||||
res = self._genResults(s, attribs, books, url, bold, 'title')
|
res = self._genResults(s, attribs, books, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -427,9 +449,12 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s (%(media)s), by %(artist)s; published by ' \
|
s = '%(title)s (%(media)s), by %(artist)s; published by ' \
|
||||||
'%(publisher)s; price: %(price)s%(url)s'
|
'%(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByArtist(artist, product_line=product)
|
items = amazon.searchByArtist(artist, product_line=product,
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
locale=region)
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -468,9 +493,12 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \
|
s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \
|
||||||
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByActor(actor, product_line=product)
|
items = amazon.searchByActor(actor, product_line=product,
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
locale=region)
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -509,9 +537,12 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \
|
s = '%(title)s (%(media)s), rated %(mpaa)s; released ' \
|
||||||
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
'%(date)s; published by %(publisher)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByDirector(director, product_line=product)
|
items = amazon.searchByDirector(director, product_line=product,
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
locale=region)
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -548,10 +579,13 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
'URL' : 'url'
|
'URL' : 'url'
|
||||||
}
|
}
|
||||||
s = '%(title)s; price: %(price)s%(url)s'
|
s = '%(title)s; price: %(price)s%(url)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
items = amazon.searchByManufacturer(manufacturer,
|
items = amazon.searchByManufacturer(manufacturer,
|
||||||
product_line=product)
|
product_line=product,
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
locale=region)
|
||||||
res = self._genResults(s, attribs, items, url, bold, 'title')
|
res = self._genResults(s, attribs, items, url, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
irc.reply(utils.commaAndify(res))
|
irc.reply(utils.commaAndify(res))
|
||||||
|
@ -565,9 +599,6 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
if not self.registryValue('linkSnarfer', msg.args[0]):
|
if not self.registryValue('linkSnarfer', msg.args[0]):
|
||||||
return
|
return
|
||||||
match = match.group(1)
|
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',
|
attribs = {'ProductName' : 'title',
|
||||||
'Manufacturer' : 'publisher',
|
'Manufacturer' : 'publisher',
|
||||||
'Authors' : 'author',
|
'Authors' : 'author',
|
||||||
|
@ -579,9 +610,11 @@ class Amazon(callbacks.PrivmsgCommandAndRegexp):
|
||||||
}
|
}
|
||||||
s = '%(title)s; %(artist)s; %(author)s; %(mpaa)s; %(media)s; '\
|
s = '%(title)s; %(artist)s; %(author)s; %(mpaa)s; %(media)s; '\
|
||||||
'%(date)s; %(publisher)s; price: %(price)s'
|
'%(date)s; %(publisher)s; price: %(price)s'
|
||||||
|
chan = msg.args[0]
|
||||||
|
region = self.registryValue('region', chan)
|
||||||
|
bold = self.registryValue('bold', chan)
|
||||||
try:
|
try:
|
||||||
item = amazon.searchByASIN(match)
|
item = amazon.searchByASIN(match, locale=region)
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
|
||||||
res = self._genResults(s, attribs, item, False, bold, 'title')
|
res = self._genResults(s, attribs, item, False, bold, 'title')
|
||||||
if res:
|
if res:
|
||||||
res = utils.commaAndify(res)
|
res = utils.commaAndify(res)
|
||||||
|
|
Loading…
Reference in New Issue