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)
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)
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
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)
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)
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
# -*- 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
""" 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),
'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:
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):