当前位置: 首页>>代码示例>>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;未经允许,请勿转载。