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 jsonify(node): xslt_root = etree.parse(XSLT) transform = etree.XSLT(xslt_root) result = transform(node) return unicode(result) if __name__ == '__main__': api = API(locale='de') collection = [] while True: try: ean = raw_input('EAN? ') resp = api.item_lookup(ean, SearchIndex='All', IdType='EAN', ResponseGroup='Large') items = resp.Items.Item for item in items: attrs = item.ItemAttributes director = None if hasattr(attrs, 'Director'): if len(attrs.Director) > 1: director = [p.text for p in attrs.Director] else: director = attrs.Director.text collection += [{ 'id': str(uuid.uuid4()), 'ean': attrs.EAN.text, 'title': attrs.Title.text,
import sys from amazonproduct.api import API if __name__ == '__main__': if len(sys.argv[1:]) == 0: print __doc__ print 'Usage: %s ISBN' % sys.argv[0] sys.exit(1) for isbn in sys.argv[1:]: isbn = isbn.replace('-', '') # Don't forget to create file ~/.amazon-product-api # with your credentials (see docs for details) api = API(locale='us') for root in api.item_lookup(isbn, IdType='ISBN', SearchIndex='Books', ResponseGroup='EditorialReview'): nspace = root.nsmap.get(None, '') reviews = root.xpath('//aws:EditorialReview', namespaces={'aws': nspace}) for review in reviews: print unicode(review.Source) print '-' * 40 print unicode(review.Content)
""" Custom response parser using BeautifulSoup to parse the returned XML. """ def parse(self, fp): soup = BeautifulSoup.BeautifulSoup(fp.read()) # parse errors 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__': # Don't forget to create file ~/.amazon-product-api # with your credentials (see docs for details) api = API(locale='us', processor=SoupProcessor()) result = api.item_lookup('0718155157') print result # ... # now do something with it!
from xml.dom.minidom import parse def minidom_response_parser(fp): """ Custom response parser using xml.dom.minidom.parse instead of lxml.objectify. """ root = parse(fp) # parse errors for error in root.getElementsByTagName('Error'): code = error.getElementsByTagName('Code')[0].firstChild.nodeValue msg = error.getElementsByTagName('Message')[0].firstChild.nodeValue raise AWSError(code, msg) return root if __name__ == '__main__': api = API(AWS_KEY, SECRET_KEY, 'us', processor=minidom_response_parser) root = api.item_lookup('0718155157') print root.toprettyxml() # ... # now do something with it!
Get all editorial reviews for books with the specified ISBNs. """ import sys from amazonproduct.api import API if __name__ == '__main__': if len(sys.argv[1:]) == 0: print __doc__ print 'Usage: %s ISBN' % sys.argv[0] sys.exit(1) for isbn in sys.argv[1:]: isbn = isbn.replace('-', '') # Don't forget to create file ~/.amazon-product-api # with your credentials (see docs for details) api = API(locale='us') for root in api.item_lookup(isbn, IdType='ISBN', SearchIndex='Books', ResponseGroup='EditorialReview'): nspace = root.nsmap.get(None, '') reviews = root.xpath('//aws:EditorialReview', namespaces={'aws' : nspace}) for review in reviews: print unicode(review.Source) print '-' * 40 print unicode(review.Content)
class SoupProcessor(BaseProcessor): """ Custom response parser using BeautifulSoup to parse the returned XML. """ def parse(self, fp): soup = BeautifulSoup.BeautifulSoup(fp.read()) # parse errors 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__': # Don't forget to create file ~/.amazon-product-api # with your credentials (see docs for details) api = API(locale='us', processor=SoupProcessor()) result = api.item_lookup('0718155157') print result # ... # now do something with it!
# -*- 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.BeautifulSoup(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_lookup('B00LCL7A3G') print result
# Don't forget to create file ~/.amazon-product-api # with your credentials (see docs for details) api = API(locale=options.locale) params = { 'ResponseGroup' : 'Images', 'SearchIndex' : 'All', 'IdType' : options.id_type, } # When IdType equals ASIN, SearchIndex cannot be present. if options.id_type == ASIN: del params['SearchIndex'] for id in ids: id = id.replace('-', '') if options.verbose: print 'Fetching info for %s...' % id root = api.item_lookup(id, **params) #~ from lxml import etree #~ print etree.tostring(root, pretty_print=True) url = root.Items.Item.LargeImage.URL.pyval name, ext = os.path.splitext(url) path = '%s%s' % (id, ext) if options.verbose: print 'Downloading %s to %s ...' % (url, path) fetch_image(url, path)