本文整理汇总了Python中amazonproduct.API.item_search方法的典型用法代码示例。如果您正苦于以下问题:Python API.item_search方法的具体用法?Python API.item_search怎么用?Python API.item_search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazonproduct.API
的用法示例。
在下文中一共展示了API.item_search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AmazonMovies
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
class AmazonMovies(object):
def __init__(self, titles):
self._pattern1 = re.compile(r"(\[.*\]|\(.*\)|【.*】|<.*>|(.*)|〔.*〕)")
self._pattern2 = re.compile(r"(DVD|Blu-ray|ブルーレイ|枚組).*")
self._pattern3 = re.compile(r"\s.*(MovieNEX|2D|3D|エディション|ディスク|特別(編|版)).*")
self._pattern4 = re.compile(r"\s$")
self._api = API(cfg=amazon_keys.config)
self._input_movies = self.get_movie_dict(titles)
self.movies_dict = self.get_similarproducts(self._input_movies)
self.movies = self.get_titles(self.movies_dict)
def get_movie_dict(self, titles):
tmp_list = []
for title in titles:
tmp_list.append({'title': title, 'asin': self.get_asin(title)})
return tmp_list
def get_asin(self, title):
time.sleep(2) # 1.8sのインターバルあれば制限に引っかからない?
asin = u""
try:
for items in self._api.item_search('DVD', Keywords=title, limit=1):
for item in items:
asin = unicode(item.ASIN)
break
break
except AWSError, e:
print("code:%s message:%s" % (e.code, e.message))
return asin
示例2: search_on_amazon
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def search_on_amazon(asin, album, artist):
'''
Tries to locate the url of album by artis on amazon
Returns '' if it can't be found
'''
from amazonproduct import API
if not AMAZON_KEY or not AMAZON_SECRET or not AMAZON_ASSOCIATE_TAG:
return ''
api = API(AMAZON_KEY, AMAZON_SECRET, 'us')
try:
if asin:
node = api.item_lookup(asin, AssociateTag=AMAZON_ASSOCIATE_TAG)
for item in node.Items:
attributes = item.Item.ItemAttributes
if attributes.ProductGroup == 'Music':
url = item.Item.DetailPageURL
if url:
return url.text
node = api.item_search('MP3Downloads', Keywords=album + ' ' + artist, AssociateTag=AMAZON_ASSOCIATE_TAG)
for item in node.Items:
attributes = item.Item.ItemAttributes
if matching.match(artist, str(attributes.Creator)) \
and matching.match(album, str(attributes.Title)) \
and attributes.ProductGroup == 'Digital Music Album':
url = item.Item.DetailPageURL
if url:
return url.text
except :
pass
return ''
示例3: lookup_price
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def lookup_price(searchTerm):
AWS_KEY = 'AKIAIILUNE5IYH7BDF2A'
SECRET_KEY = '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'
ASSOC_TAG = 'camerarecomm-20'
api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)
price = -1
title = ''
try:
results = api.item_search('Electronics', Keywords=searchTerm,
BrowseNode='281052', ResponseGroup='Large', ItemPage=1)
if results is not None:
for cam in results:
try:
#asin = cam.Items.Item.ASIN
title = cam.Items.Item.ItemAttributes.Title.text
price = cam.Items.Item.ItemAttributes.ListPrice.FormattedPrice.text
# print title, price
break
except:
price = -1
title = ''
except:
print 'Item not found'
return price, title
示例4: AmazonChecker
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
class AmazonChecker(object):
def __init__(self):
AWS_KEY = ''
SECRET_KEY = ''
ASSOCIATE_TAG = 'stream0a-20'
self.api = API(AWS_KEY, SECRET_KEY, 'us', ASSOCIATE_TAG)
#self.api = JSONAPI(AWS_KEY, SECRET_KEY, 'us')
def availability(self, needle):
#Instant Video browse node: 16261631 or maybe 2649513011
#api.call(Operation='ItemSearch', SearchIndex='Video') #US/Video? 493964
#data = self.api.browse_node_lookup(16261631)
#data = self.api.item_lookup('B0047WJ11G', **params)
#data = self.api.item_lookup('Inception', **params)
#data = self.api.item_search("DVD", Title="Inception", ResponseGroup="Large")
try:
data = self.api.item_search("Video", Title=needle, BrowseNode="16261631")
except NoExactMatchesFound:
return [{"service":"amazon-instant", "available":False}]
#print data
#print dir(data)
#for root in data:
# print "root"
# print dir(root.Items.Item.ItemAttributes)
# print root.Items.Item.ItemAttributes.Title
#pp = pprint.PrettyPrinter(indent=3)
return [{"service":"amazon-instant", "available":True}]
示例5: search
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def search(title=''):
"""Amazon quick search function."""
api = API(LOG['AWS_KEY'], LOG['SECRET_KEY'], LOG['LOCAL'], LOG['ASSOC_TAG'])
node = api.item_search('Books', Title=title, Publisher=publisher)
for page in node:
for book in page.Items.Item:
print '%s' % (book.ASIN)
示例6: search
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def search():
api = API(locale="jp")
# total_results = node.Items.TotalResults.pyval
# total_pages = node.Items.TotalPages.pyval
for book in api.item_search("Books", Publisher=u"村上"):
try:
print "%s" % (book.ItemAttributes.Title)
# print '%s: "%s"' % (book.ItemAttributes.Author,
# book.ItemAttributes.Title)
except:
logging.debug("no author or title")
示例7: search
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def search(self, q, country):
titles = []
prices = []
urls= []
items = []
api = API(AWS_KEY, SECRET_KEY, country)
try:
for root in api.item_search('Books', Title=q, AssociateTag='...', ResponseGroup='Large'):
# extract paging information
total_results = root.Items.TotalResults.pyval
total_pages = root.Items.TotalPages.pyval
try:
current_page = root.Items.Request.ItemSearchRequest.ItemPage.pyval
except AttributeError:
current_page = 1
#print 'page %d of %d' % (current_page, total_pages)
#~ from lxml import etree
#~ print etree.tostring(root, pretty_print=True)
nspace = root.nsmap.get(None, '')
books = root.xpath('//aws:Items/aws:Item',
namespaces={'aws' : nspace})
#return unicode(books[0].ItemAttributes.Title)
for book in books:
items.append(unicode(book.ItemAttributes.Title))
#print book.ASIN,
#if hasattr(book.ItemAttributes, 'Author'):
#print unicode(book.ItemAttributes.Author), ':',
#print unicode(book.ItemAttributes.Title),
#price_offers(book.ASIN)
try:
if hasattr(book.ItemAttributes, 'ListPrice'):
#print unicode(book.ItemAttributes.ListPrice.FormattedPrice)
items.append(unicode(book.ItemAttributes.ListPrice.FormattedPrice))
elif hasattr(book.OfferSummary, 'LowestUsedPrice'):
#print u'(used from %s)' % book.OfferSummary.LowestUsedPrice.FormattedPrice
items.append(unicode(book.OfferSummary.LowestUsedPrice.FormattedPrice))
except:
items.append("No price info.")
items.append(unicode(book.DetailPageURL))
#print '\n'
#print len(items)
return items
except:
return items
示例8: searchAmazon
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def searchAmazon(API):
hash_of_items = {}
try:
for item in API.item_search('VideoGames', Title='Amiibo', MerchantId="Amazon", Availability="Available"):
product = item.ItemAttributes
product_name = product.Title
product_manufacturer = product.Manufacturer.text
product_url = item.DetailPageURL.text
if 'Nintendo' in product_manufacturer:
hash_of_items.update({product_name: product_url})
except:
print "NAH"
return hash_of_items
示例9: AmazonDvd
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
class AmazonDvd():
def __init__(self):
self.api = API(locale='us')
def find_product(self, keywords, Director=None):
'''
return top 10 products
'''
items = self.api.item_search(
'DVD', Keywords=keywords, Director=None, limit=10,
Sort='relevancerank', MerchantId='Amazon', ResponseGroup='Large')
dvds = []
for item in items:
json_obj = json.loads(ObjectJSONEncoder().encode(item))
dvd = {}
dvd['ASIN'] = json_obj['ASIN']
dvd['Title'] = json_obj['ItemAttributes']['Title']
dvd['DetailPageURL'] = json_obj['DetailPageURL']
if json_obj.get('SmallImage', None):
dvd['SmallImage'] = json_obj['SmallImage']['URL']
if json_obj.get('CustomerReviews', None):
dvd['CustomerReviews'] = json_obj['CustomerReviews']['IFrameURL']
if json_obj.get('EditorialReviews', None):
dvd['EditorialReviews'] = json_obj[
'EditorialReviews']['EditorialReview']['Content']
if json_obj.get('OfferSummary', None):
dvd['LowestNewPrice'] = json_obj['OfferSummary'][
'LowestNewPrice']['FormattedPrice']
if json_obj['ItemAttributes'].get('Actor', None):
dvd['Actor'] = json_obj['ItemAttributes']['Actor']
if json_obj['ItemAttributes'].get('Director', None):
dvd['Director'] = json_obj['ItemAttributes']['Director']
dvds.append(dvd)
return dvds
示例10: amazon_res
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def amazon_res(page_type, words):
api = API(locale='us')
if page_type == 'food':
topic = 'Grocery'
else:
topic = 'HomeGarden'
results = api.item_search(topic , Keywords=words, ResponseGroup="ItemAttributes, OfferSummary, Images", paginate = False)
items = []
for it in results.Items.Item:
asin = it.ASIN
title = it.ItemAttributes.Title
link = it.DetailPageURL
try:
price = it.OfferSummary.LowestNewPrice.FormattedPrice
except:
price = "no price available"
try:
image = it.SmallImage.URL
except:
image = ""
if page_type == 'food':
try:
item = Food.objects.get(asin=asin)
print(item.name)
except:
item = False
print('doesnt exist')
else:
try:
item = Equipment.objects.get(asin=asin)
except:
item = False
items.append({'asin':asin, 'title':title, 'link':link, 'price':price, 'image':image, 'db':item})
return items
示例11: search
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
def search():
print "hello"
search_text = request.args['q']
region = request.args['region']
listed = True
try:
api = API(locale='us')
products = api.item_search('All', Keywords=search_text, paginate=False, ResponseGroup="ItemIds, ItemAttributes, Images, OfferSummary, Offers")
niceProducts = []
ASINList = []
for product in products.Items.Item:
try:
niceProduct = Product()
niceProduct.title = product.ItemAttributes.Title
niceProduct.ASIN = product.ASIN.text
ASINList.append(niceProduct.ASIN)
niceProduct.imageUrl = product.MediumImage.URL
try:
niceProduct.newPrice = float(product.OfferSummary.LowestNewPrice.Amount)/100
niceProduct.newFormattedPrice = product.OfferSummary.LowestNewPrice.FormattedPrice
niceProduct.newPriceCurrency = product.OfferSummary.LowestNewPrice.CurrencyCode
except:
pass
try:
niceProduct.usedPrice = float(product.OfferSummary.LowestUsedPrice.Amount)/100
niceProduct.usedFormattedPrice = product.OfferSummary.LowestUsedPrice.FormattedPrice
niceProduct.usedPriceCurrency = product.OfferSummary.LowestUsedPrice.CurrencyCode
except:
pass
niceProduct.type = product.ItemAttributes.ProductGroup
niceProduct.region = getRegionFromUrl(product.DetailPageURL.text).upper() #product.ItemAttributes.RegionCode
niceProduct.locale = getRegionFromUrl(product.DetailPageURL.text)
niceProduct.model = product.ItemAttributes.Model
niceProducts.append(niceProduct)
if not listed:
print(objectify.dump(product))
listed = True
except:
pass
#not a product
# res = api.item_lookup(*ASINList, MerchantId='Amazon', ResponseGroup = 'Offers')
# i = 0
# listed = False
# for amazonProduct in res.Items.Item:
# print 'new amazon offer for ASIN : ', amazonProduct.ASIN
# print '#########################################'
#print objectify.dump(amazonProduct)
# try:
#print 'not void!'
#for offer in amazonProduct.Offers:
# print objectify.dump(amazonProduct)
# niceProducts[i].newPrice = float(amazonProduct.OfferSummary.LowestNewPrice.Amount)/100
# niceProducts[i].newFormattedPrice = amazonProduct.OfferSummary.LowestNewPrice.FormattedPrice
# niceProducts[i].newPriceCurrency = amazonProduct.OfferSummary.LowestNewPrice.CurrencyCode
# print 'price is : ', float(amazonProduct.OfferSummary.LowestNewPrice.Amount)/100
# except Exception as inst:
# print inst
#if not listed:
# print(objectify.dump(amazonProduct))
# listed = True
#try:
## print 'set price : ', i, ', ASIN : ', amazonProduct.ASIN
## niceProducts[i].newPrice = float(amazonProduct.ItemAttributes.ListPrice.Amount)/100
## niceProducts[i].newFormattedPrice = amazonProduct.ItemAttributes.ListPrice.FormattedPrice
## niceProducts[i].newPriceCurrency = amazonProduct.ItemAttributes.ListPrice.CurrencyCode
## print 'ok price for : ', i
##except:
# pass
# i+=1
except errors.AWSError, e:
print 'Amazon complained about yout request!'
print e.code
print e.msg
return e.msg
示例12: API
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
from amazonproduct import API
api = API(locale='us')
items = api.item_search('leisure women summer vacation girls')
# get all books from result set and
# print author and title
for item in items:
print 'Title: "%s"' % (item.ItemAttributes.Title)
# import keys
# from amazon.api import AmazonAPI
# AMAZON_ACCESS_KEY = keys.AMAZON_ACCESS_KEY
# AMAZON_SECRET_KEY = keys.AMAZON_SECRET_KEY
# AMAZON_ASSOC_TAG = keys.AMAZON_ASSOC_TAG
# amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
# products = amazon.search(Keywords='kindle', SearchIndex='All')
# for i, product in enumerate(products):
# print "{0}. '{1}'".format(i, product.title)
示例13: NetflixDisc
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
# a specific title based on the 'links'
# which include formats, synopsis, etc.
######################################
disc = NetflixDisc(movie['catalog_title'],netflix)
formats = disc.getInfo('formats')
return formats
if __name__ == '__main__':
amazon_only = []
#Get list of bestselling Amazon movies
abestselling = []
api = API(AWS_KEY, SECRET_KEY, 'us')
for i in range(4):
node = api.item_search('UnboxVideo', BrowseNode='16386761', ItemPage=i+1)
for movie in node.Items.Item:
abestselling.append(movie.ItemAttributes.Title)
print abestselling
#Query titles on Netflix and find earliest availability date. If it's in the future - it's available on Amazon but not Netflix.
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK, 'False')
for film in abestselling:
discs = []
time.sleep(1)# Note that we have to sleep between queries to avoid the per-second cap on the API
doSearch(netflixClient, discs, film)
time.sleep(1)
movie = getTitleFromID(netflixClient,discs[0]['id'])
time.sleep(1)
formats = getTitleInfo(netflixClient,movie)
示例14: exit
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
if AWS_KEY == "":
exit(0)
if len(sys.argv) > 1:
uartist = sys.argv[1]
ualbum = sys.argv[2]
utrack = sys.argv[3]
else:
exit(0)
score = 0
url = {"Amazon": ""}
api = API(AWS_KEY, SECRET_KEY, "us")
node = api.item_search("Music", Artist=uartist, Title=ualbum, Track=utrack, ResponseGroup="Large")
for item in node.Items.Item:
if not hasattr(item, "Tracks"):
continue
if uartist != item.ItemAttributes.Artist.pyval and not cjb.simple_compare(
uartist, item.ItemAttributes.Artist.pyval, 0.90
):
continue
albumscore = 0
if ualbum == item.ItemAttributes.Title:
albumscore += 32
elif cjb.simple_compare(ualbum, item.ItemAttributes.Title.pyval, 0.80):
albumscore += 20
示例15: open
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import item_search [as 别名]
with open('cmn_games2.csv', 'r') as op:
cmn_gms = csv.reader(op)
for row in cmn_gms:
cmn_games.extend(row)
print len(cmn_games)
game_list = []
for game in cmn_games:
for plt in ['PC', 'Xbox One', 'Playstation 4']:
game_dict = dict()
game_dict['Title'] = game
game_dict['Platform'] = plt
try:
print game + ' ' + plt + '\n'
ress = api.item_search('VideoGames', Keywords=game + ' ' + plt)
for res in ress:
root = res
# xml_new = etree.tostring(root, pretty_print=True)
# print xml_new
game_dict['Amzn_Title'] = root.ItemAttributes.Title
asin = root.ASIN.text
sleep(2)
result0 = api.item_lookup(asin,ResponseGroup='OfferSummary')
game_dict['Price'] = result0.Items.Item.OfferSummary.LowestNewPrice.FormattedPrice.text
sleep(2)
result = api.item_lookup(asin,ResponseGroup='Reviews', TruncateReviewsAt=10)
review_link = result.Items.Item.CustomerReviews.IFrameURL.text
response = urllib2.urlopen(review_link).read()
soup = BeautifulSoup(response)
try: