本文整理汇总了Python中amazon.api.AmazonAPI.lookup方法的典型用法代码示例。如果您正苦于以下问题:Python AmazonAPI.lookup方法的具体用法?Python AmazonAPI.lookup怎么用?Python AmazonAPI.lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazon.api.AmazonAPI
的用法示例。
在下文中一共展示了AmazonAPI.lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
class GiftlyAmazonAPI:
amazon_product_details = ['api', 'asin', 'author', 'authors',
'aws_associate_tag', 'binding', 'brand',
'browse_nodes', 'color', 'creators', 'ean',
'edition', 'editorial_review', 'editorial_reviews',
'eisbn', 'features', 'get_attribute',
'get_attribute_details', 'get_attributes',
'get_parent', 'images', 'isbn', 'label', 'languages',
'large_image_url', 'list_price', 'manufacturer',
'medium_image_url', 'model', 'mpn', 'offer_url',
'pages', 'parent', 'parent_asin', 'parsed_response',
'part_number', 'price_and_currency', 'publication_date',
'publisher', 'region', 'release_date', 'reviews', 'sales_rank',
'sku', 'small_image_url', 'tiny_image_url', 'title',
'to_string', 'upc']
amazon_search_index = ['All','Apparel','Appliances','ArtsAndCrafts','Automotive', 'Baby',
'Beauty','Blended','Books','Classical','Collectibles','DVD',
'DigitalMusic','Electronics', 'GiftCards','GourmetFood','Grocery',
'HealthPersonalCare','HomeGarden','Industrial','Jewelry', 'KindleStore',
'Kitchen','LawnAndGarden','Marketplace','MP3Downloads','Magazines','Miscellaneous',
'Music','MusicTracks','MusicalInstruments','MobileApps','OfficeProducts','OutdoorLiving',
'PCHardware', 'PetSupplies','Photo','Shoes','Software','SportingGoods',
'Tools','Toys','UnboxVideo','VHS','Video', 'VideoGames','Watches','Wireless','WirelessAccessories']
def __init__(self, secret_key, access_key, assoc_tag):
self.amazon = AmazonAPI(access_key, secret_key, assoc_tag)
#Keywords is a comma-separated string
#Returns a dictionary of products mapped as ASIN:TITLE
#Can Android parse for keys? We'll find out...
def get_similar_items(self, keywords, numitems=None, category=None):
keywords = keywords if keywords else None
numitems = numitems if numitems else 10
category = category if category else 'All'
print "%d items found with keywords %s in the %s category" % (numitems, keywords, category)
products = self.amazon.search_n(numitems, Keywords=keywords, SearchIndex=category)
product_dict = {}
for product in products:
product_dict[product.asin] = product.title
return product_dict
def get_item_by_asin(self, asin):
product = self.amazon.lookup(ItemId=asin)
product = AmazonProduct(product.asin, product.title)
return product.get_product()
#asin_list is a list of individual asin strings
#they are joined together as one large string
def get_items_by_asin(self, asin_list):
product_list = []
products = self.amazon.lookup(ItemId=(asin_list))
for product in products:
product_list.append(AmazonProduct(product.asin, product.title).get_product())
print product_list
return product_list
示例2: AmazonScraper
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
class AmazonScraper(object):
def __init__(self, access_key, secret_key, associate_tag, *args, **kwargs):
self.api = AmazonAPI(access_key, secret_key, associate_tag, *args, **kwargs)
def reviews(self, ItemId=None, URL=None):
return Reviews(self, ItemId, URL)
def review(self, Id=None, URL=None):
return Review(self, Id, URL)
def lookup(self, URL=None, **kwargs):
if URL:
kwargs['ItemId'] = extract_asin(URL)
result = self.api.lookup(**kwargs)
if isinstance(result, (list, tuple)):
result = [Product(p) for p in result]
else:
result = Product(result)
return result
def similarity_lookup(self, **kwargs):
for p in self.api.similarity_lookup(**kwargs):
yield Product(p)
def browse_node_lookup(self, **kwargs):
return self.api.browse_node_lookup(**kwargs)
def search(self, **kwargs):
for p in self.api.search(**kwargs):
yield Product(p)
def search_n(self, n, **kwargs):
for p in self.api.search_n(n, **kwargs):
yield Product(p)
示例3: Item
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
class Item(object):
def __init__(self, product):
self.product = product
self.amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
def prod_search(self):
products_found = self.amazon.search_n(1, Keywords= self.product, SearchIndex= "All")
return products_found
def prod_item(self):
products_found = self.prod_search()
try:
return products_found[0].title
except IndexError:
raise Exception('No product found')
def prod_asin(self):
products_found = self.prod_search()
try:
return products_found[0].asin
except IndexError:
raise Exception('No Asin found')
def prod_price(self):
product_asin = self.prod_asin()
the_product = self.amazon.lookup(ItemId='' + product_asin + '')
found_product_price = the_product.price_and_currency
print the_product.image
return found_product_price
示例4: update_price
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def update_price(self):
# check if this is an Amazon product
if self.distributor.name == 'Amazon':
amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG)
try:
product = amazon.lookup(ItemId=self.part.asin)
price = product.price_and_currency
return price[0]
except:
pass
else:
import urllib2
from lxml import etree
import microdata
import urllib
items = microdata.get_items(urllib.urlopen(self.url))
for i in items:
if i.offers:
return "%s (md)".replace("$", "") % i.offers.price.strip().replace("$", "")
html = urllib2.urlopen(self.url).read()
tree = etree.HTML(html)
price = tree.xpath("%s/text()[1]" % self.xpath)
try:
return "%s (xp)" % price[0].replace("$", "")
except:
return "N/A"
示例5: handle
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def handle(self, *args, **options):
amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG)
two_days_ago = date.today() - timedelta(days=2)
# isbns = [book.isbn for book in Book.objects.filter(mod_date__gte=two_days_ago)]
isbns = [book.isbn for book in Book.objects.all()]
grouped_isbns = map(None, *[iter(isbns)]*10)
print "=== Start daily book update."
for index, isbns in enumerate(grouped_isbns):
isbns = filter(None, isbns)
isbns = ",".join(isbns)
print " == index : %s / items : %s" % (str(index), isbns)
amazon_books = amazon.lookup(ItemId=isbns)
for amazon_book in amazon_books:
try:
dbbook = Book.objects.get(isbn__exact=amazon_book.isbn)
dbbook.update(amazon_book)
except Book.DoesNotExist:
Book.objects.create_book(amazon_book)
time.sleep(4)
print "=== Successful updated all books"
示例6: asin_image
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def asin_image(self):
amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG)
try:
product = amazon.lookup(ItemId=self.asin)
return product.large_image_url
except:
return None
示例7: amazon_price
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def amazon_price(self):
amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG)
try:
product = amazon.lookup(ItemId=self.asin)
price = product.price_and_currency
return "$%.2f %s" % (price[0], price[1])
except:
return None
示例8: amazonResults
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def amazonResults(amazonID):
'''Puts ASIN through Amazon API and returns item title, price, and image'''
amazon = AmazonAPI(amazonAccessKey, amazonSecretKey, amazonAssocTag)
product = amazon.lookup(ItemId=amazonID)
title = product.title
image = product.large_image_url
price = product.price_and_currency
return title, price, image
示例9: add_book
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def add_book(request, isbn):
amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG)
amazon_book = amazon.lookup(ItemId=isbn)
Book.objects.create_book(amazon_book)
if request.is_ajax():
return HttpResponse(status=200)
else:
return HttpResponseRedirect(request.META.get("HTTP_REFERER", ""))
示例10: get
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def get(self):
amazon = AmazonAPI()
watches = models.get_db_watches()
if watches:
for WatchListing in watches:
product = amazon.lookup(ItemId=WatchListing.ItemId)
WatchListing.Price = product.price_and_currency[0]
WatchListing.put()
time.sleep(1) #amazon only allows a single API per second...
return
示例11: prod_price
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def prod_price(self, product_asin):
#insert amazon web services credentials
AMAZON_ACCESS_KEY = 'AKIAJGEKFL3UEU6QMCPQ'
AMAZON_SECRET_KEY = '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'
#associate TAG must be updated every 180 days, make new amazon associates account to get new tag
AMAZON_ASSOC_TAG = 'ignacio0ba-20'
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
the_product = amazon.lookup(ItemId='' + product_asin + '')
found_product_price = the_product.price_and_currency
示例12: __init__
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
class AmazonController:
def __init__(self):
keys = Amazon.objects.all()
key = keys[0]
self.amazon = AmazonAPI(key.access_key.encode('ascii'), key.secret_key.encode('ascii'), key.assoc_tag.encode('ascii'))
def lookup(self, item_id, id_type = 'ASIN', search_index = ''):
try:
response = self.amazon.lookup(ItemId = item_id, IdType = id_type, SearchIndex = search_index)
return response
except:
return None
示例13: fetch_from_amazon
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def fetch_from_amazon(game):
title = ''.join(('NES ', game.title))
AMAZON_ACCESS = os.environ['AMAZON_ACCESS']
AMAZON_SECRET = os.environ['AMAZON_SECRET']
AMAZON_AWS = os.environ['AMAZON_AWS']
amazon = AmazonAPI(AMAZON_ACCESS, AMAZON_SECRET,AMAZON_AWS)
try:
products = amazon.search_n(1, Keywords=title, Condition='Used', SearchIndex = 'VideoGames')
return amazon.lookup(ItemId=products[0].asin, Condition='Used')
# if above fails the template handles the error
except:
pass
示例14: get_amazon_product_meta
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def get_amazon_product_meta(url):
# the input URL is always of amazon
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="IN")
item_id = get_amazon_item_id(url)
if not item_id:
return None
try:
product = amazon.lookup(ItemId=item_id)
except amazon.api.AsinNotFound:
# log this ASIN
return None
# product.price_and_currency returns in the form (price, currency)
product_price = product.price_and_currency[0]
示例15: createCart
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup [as 别名]
def createCart(products):
pdict = {}
for item in products:
if item in pdict:
pdict[item] = pdict[item] + 1
else:
pdict[item] = 1
amazon = AmazonAPI(ACCESS_KEY, SECRET_KEY, ASSOC_ID)
for index, key in enumerate(pdict.items()):
product = amazon.lookup(ItemId=key[0])
item = {'offer_id': product.offer_id, 'quantity': key[1]}
if index == 0:
cart = amazon.cart_create(item)
else:
cart = amazon.cart_add(item, cart.cart_id, cart.hmac)
return cart