當前位置: 首頁>>代碼示例>>Python>>正文


Python API.item_search方法代碼示例

本文整理匯總了Python中amazonproduct.api.API.item_search方法的典型用法代碼示例。如果您正苦於以下問題:Python API.item_search方法的具體用法?Python API.item_search怎麽用?Python API.item_search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在amazonproduct.api.API的用法示例。


在下文中一共展示了API.item_search方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: amazon

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
def amazon(query):

    api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)

    similar_root = api.similarity_lookup('B0058U6DQC', ResponseGroup='Large')

    product_root = api.item_lookup('B0058U6DQC', ResponseGroup='Large')
    product_root =  api.item_search(title='unicorn', ResponseGroup='Large')
    more_products = api.item_search('Books', Publisher='Galileo Press')
    #~ from lxml import etree
    #~ print etree.tostring(root, pretty_print=True)

    nspace = similar_root.nsmap.get(None, '')
    similar_products = similar_root.xpath('//aws:Items/aws:Item', 
                         namespaces={'aws' : nspace})

    # more_products = product_root.xpath('//aws:Items/aws:Item', 
    #                      namespaces={'aws' : nspace})

    return render_template("amazon.html", similar_products=similar_products, more_products = more_products, query=query)
開發者ID:tatertot,項目名稱:lendinglibrary,代碼行數:22,代碼來源:borrow.py

示例2: getAmazonContent

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
def getAmazonContent(query):

	api = API(AWS_KEY, SECRET_KEY, 'uk', associate_tag='giracake-21', processor=minidom_response_parser)
	node = api.item_search('All', Keywords=query, ResponseGroup="Medium")
	products = node.getElementsByTagName('Item')

	data = []

	for product in products:
		#print product.toprettyxml()
		summaryNodes = product.getElementsByTagName('OfferSummary')

		if len(summaryNodes) > 0:
			for summaryNode in summaryNodes:
				priceNodes = summaryNode.getElementsByTagName('LowestNewPrice')

				for priceNode in priceNodes:
					formattedPrice = priceNode.getElementsByTagName('FormattedPrice')

					price = formattedPrice[0].childNodes[0].nodeValue

		imageSetsNodes = product.getElementsByTagName('ImageSets')

		if len(imageSetsNodes) > 0:
			for imageSetsNode in imageSetsNodes:
				imageSetNodes = imageSetsNode.getElementsByTagName('ImageSet')

				for imageSetNode in imageSetNodes:
					if imageSetNode.attributes["Category"].value != "primary":
						continue

					mediumImage = imageSetNode.getElementsByTagName('LargeImage')

					url = mediumImage[0].getElementsByTagName('URL')[0]

					image = url.childNodes[0].nodeValue


		prod = {}
		prod['url'] = getText(product.getElementsByTagName('DetailPageURL')[0].childNodes)
		prod['title'] = getText(product.getElementsByTagName('Title')[0].childNodes)
		prod['img'] = image
		prod['price'] = price
		#imagesets = getText(product.getElementsByTagName('MediumImage'))[0].childNodes
		#print imagesets
		#imageset = getText(imagesets.getElementsByTagName('ImageSet'))[0]

		data += [prod]

	return data
開發者ID:Jbalkind,項目名稱:Amazon-Hackathon,代碼行數:52,代碼來源:amazon.py

示例3: amazon_search

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
def amazon_search():
    api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)
    result = api.item_search('All',
        ResponseGroup='Large', AssociateTag='boitba-20', Keywords='tent marmot', ItemPage=2)

    total_results = result.results

    #item_search returns pages not items

    # extract paging information
    #total_results = result.results
    #Stotal_pages = len(result)  # or result.pages

    #~ from lxml import etree
    #~ print etree.tostring(root, pretty_print=True)
  

    return render_template("amazon_search.html", node = result, total_results=total_results)
開發者ID:tatertot,項目名稱:lendinglibrary,代碼行數:20,代碼來源:borrow.py

示例4: AmazonProductSearch

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
class AmazonProductSearch():
    def __init__(self, aws_access_key, aws_secret_key, affiliate_key):
        self.api = API(aws_access_key, aws_secret_key, 'us', affiliate_key)

    def _create_product(self, result):
        product = {}
        product['ASIN'] = str(result.ASIN)
        product['Amount'] = str(result.OfferSummary.LowestNewPrice.Amount)
        product['Binding'] = str(result.ItemAttributes.Binding)
        product['DetailPageURL'] = str(result.DetailPageURL)
        return product

    def item_search(self, title, actor, expected_running_time,
            ResponseGroup='OfferFull, Medium', release_year=None):
        '''
        This method searches Amazon for DVD, Blu-ray, and/or Amazon Instant
        Video listings of the movie that we are searching. Actor and running
        time are included in the query to improve the accuracy of the results
        returned by Amazon.

        Args:
            title: Title of the movie
            actor: Top billing actor for the movie
            expected_running_time: Total running time for the movie
            ResponseGroup: See response group in amazon product search api
                documentation
        '''
        try:
            results = self.api.item_search('DVD', actor=actor, Keywords=title,
                         ResponseGroup=ResponseGroup)
        except Exception as e:
            print e
            return []
        
        rv = []
        max_release_year_diff = 1
        max_running_time_diff = 5
        bindings_seen = {"DVD": False, "Blu-ray": False,
                         "Amazon Instant Video": False}

        for result in results:
            etree.tostring(result, pretty_print=True)
            try:
                if all(bindings_seen.values()):
                    return rv

                result_binding = str(result.ItemAttributes.Binding)
                result_release_year = int(str(result.ItemAttributes.ReleaseDate).split('-')[0])
                result_running_time = int(result.ItemAttributes.RunningTime)
                result_title = str(result.ItemAttributes.Title)
                
                if fuzz.partial_ratio(title.lower(), result_title.lower()) < 100:
                    continue
                if release_year is not None and abs(release_year - result_release_year) > max_release_year_diff:
                    continue
                if abs(expected_running_time - result_running_time) > max_running_time_diff:
                    continue
                if result_binding not in bindings_seen.keys():
                    continue
                if bindings_seen.get(result_binding):
                    continue

                rv.append(self._create_product(result))
                bindings_seen[result_binding] = True
            except Exception as e:
                print e
                continue
        return rv
開發者ID:chenghanlee,項目名稱:tldw,代碼行數:70,代碼來源:amazon_product_search.py

示例5: SoupProcessor

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
# -*- coding: utf-8 -*-

from amazonproduct.api import API
from amazonproduct.errors import AWSError
from amazonproduct.processors import BaseProcessor

import BeautifulSoup


class SoupProcessor(BaseProcessor):
    def parse(self, fp):
        soup = BeautifulSoup.BeautifulStoneSoup(fp.read())

        for error in soup.findAll('error'):
            code = error.find('code').text
            msg = error.find('message').text
            raise AWSError(code, msg)

        return soup

if __name__ == '__main__':
    api = API(locale='jp', processor=SoupProcessor())
    result = api.item_search('Apparel', Condition='All', Availability='Available', Keywords='Shirt')

    print result
開發者ID:raindrop-aqua,項目名稱:learn-python,代碼行數:27,代碼來源:item_search.py

示例6: Connection

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
from amazonproduct.api import API
from config import AWS_KEY, SECRET_KEY

if __name__ == '__main__':

    item_attr = ['Brand', 'Manufacturer', 'Model', 'OperatingSystem', 'ProductGroup', 'ProductTypeName', 'ReleaseDate', 'Title']
    item_img = ['SmallImage', 'MediumImage', 'LargeImage']
    item_offer = ['SalesRank', 'TotalNew']
    item_price = ['LowestNewPrice', 'LowestRefurbishedPrice', 'LowestUsedPrice']
    img_attr = ['Height', 'URL', 'Width']

    connection = Connection()
    db = connection.linux_laptops

    api = API(AWS_KEY, SECRET_KEY, 'us', associate_tag='notebux-20')
    paginator = api.item_search('Electronics', Keywords='linux laptop', ResponseGroup='Medium')

    for root in paginator:
        nspace = root.nsmap.get(None, '')
        items = root.xpath('//aws:Items/aws:Item', namespaces={'aws' : nspace})

        for i in items:
            doc = {}
            try:
                doc['ASIN'] = str(i.ASIN)
                doc['URL'] = str(i.DetailPageURL)

                # Images
                doc['Images'] = {}
                for a in item_img:
                    if hasattr(i, a):
開發者ID:yaph,項目名稱:notebux,代碼行數:33,代碼來源:get_linux_laptops.py

示例7: credentials

# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.API import item_search [as 別名]
"""
Get all books published by "Galileo Press".
"""

from amazonproduct.api import API
import lxml

if __name__ == '__main__':
    
    # Don't forget to create file ~/.amazon-product-api
    # with your credentials (see docs for details)
    api = API(locale='de')

    result = api.item_search('Books', Publisher='Galileo Press',
        ResponseGroup='Large')

    # extract paging information
    total_results = result.results
    total_pages = len(result)  # or result.pages

    for book in result:

        print 'page %d of %d' % (result.current, total_pages)
        
        #~ from lxml import etree
        #~ print etree.tostring(book, pretty_print=True)
        
        print book.ASIN,
        print unicode(book.ItemAttributes.Author), ':',
        print unicode(book.ItemAttributes.Title),
開發者ID:Yappawu,項目名稱:python-amazon-product-api,代碼行數:32,代碼來源:all-galileo-titles.py


注:本文中的amazonproduct.api.API.item_search方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。