Example #1
0
def amazonsearch(query):
    from lxml import etree
    #API Access keys
    config = {
        'access_key': 'AKIAIKDCGPZIH4ZFFQGQ',
        'secret_key': 'MmVP8/U+zi3gZ23hQb88HgA/+DdA6PIF2mdQcO/9',
        'associate_tag': 'themanhproj-20',
        'locale': 'us'
    }
    #configuration of API
    api = amazonproduct.API(cfg=config)
    #search for related items
    items = api.item_search('All', Keywords=query)
    Price = 0.00
    #looks at first search result and lookups the price for it
    for stuff in items:
        #gets the ASIN number for the product
        ASIN = stuff.ASIN
        asin_string = '%s' % (ASIN)
        result = api.item_lookup(asin_string, ResponseGroup='OfferSummary')
        for item in result.Items.Item:
            print 'Name of Product: %s' % (stuff.ItemAttributes.Title)
            print 'URL Link of Product: %s' % (stuff.DetailPageURL)
            try:
                Price = int(item.OfferSummary.LowestNewPrice.Amount) / 100.0
            except AttributeError:
                x = 0
            print 'Price amount: %s' % (Price)
            #         print etree.tostring(item.OfferSummary.LowestNewPrice.Amount, pretty_print=True)
            print " "
        #only want first search result, usually the most accurate
        break
    return Price
Example #2
0
def amazon_get_asin(barcode, country, date):
    params = {
        'ResponseGroup': 'Medium,Images',
        'SearchIndex': 'Music',
        'IdType': barcode_type(barcode),
    }
    items = []
    for loc in store_map_rev[country]:
        if loc not in amazon_api:
            amazon_api[loc] = amazonproduct.API(cfg.AWS_KEY,
                                                cfg.AWS_SECRET_KEY, loc,
                                                cfg.AWS_ASSOCIATE_TAG)
        try:
            root = amazon_api[loc].item_lookup(barcode, **params)
        except amazonproduct.errors.InvalidParameterValue, e:
            continue
        item = root.Items.Item
        if not 'LargeImage' in item.__dict__:
            continue
        attrs = item.ItemAttributes
        if 'Format' in attrs.__dict__ and 'Import' in [
                f for f in attrs.Format
        ]:
            continue
        asin_barcode = ''
        if 'EAN' in attrs.__dict__:
            asin_barcode = str(attrs.EAN)
        elif 'UPC' in attrs.__dict__:
            asin_barcode = str(attrs.UPC)
        if barcode.lstrip('0') != asin_barcode.lstrip('0'):
            continue
        items.append(item)
Example #3
0
    def __init__(self):

        cred = AWSCredentials.getAWSCredentials()
        #self.amazon = amazonproduct.API(locale='us')
        self.amazon = amazonproduct.API(
            cfg='C:\Users\sujil\Documents\.amazon-product-api', locale='us')
        print("Amazon product API connected...")
Example #4
0
    def get_results(job_title):

        config = {
            'access_key': 'AKIAIAW7JXESRBCM2BLA',
            'secret_key': 'YKBHD9+IPMGYEE8/pzwYg2UOqabuivtTaUHaauyC',
            'associate_tag': '4319-1549-2008',
            'locale': 'us'
        }
        api = amazonproduct.API(cfg=config)
        #amazonproduct.API(access_key_id=Amazon.ACCESS_KEY, secret_access_key=Amazon.SECRET_KEY,associate_tag=Amazon.ASSOCIATE_TAG, locale='us')
        items = api.item_search('Books', Keywords=job_title)
        results = []

        #price = api.item_lookup('B00008OE6I', ResponseGroup='OfferFull', Condition='All')

        for x, item in enumerate(items):
            #try:

            try:
                ansi = str(item.ASIN)
                offer = api.item_lookup(ansi,
                                        ResponseGroup='OfferFull',
                                        Condition='All')
                price = str(offer.Items.Item.Offers.Offer.OfferListing.Price.
                            FormattedPrice)
                a = 1
            except:
                price = "Price Unkown"

                title = str(item.ItemAttributes.Title)
                author = str(item.ItemAttributes.Author)
                url = str(item.DetailPageURL)

                results.append({
                    'author': author,
                    'title': title,
                    'url': url,
                    'description': price,
                    'id': '',
                    'content_type': 'Article',
                })
            if x == 5:
                break

            #For Price:
            #<Items>
            #...
            #<Item>
            #...
            #<Offers>
            #    ...
            #    <Offer>
            #        ...
            #        <OfferListing>

            #Some rows don't have the author or title attributes
            #except AttributeError:
            #    pass
        return results
	def __init__(self):
		config = {}
		execfile("config.py", config)
		amazonproduct.HOSTS['mx'] = 'webservices.amazon.com.mx'
		self.api = amazonproduct.API(cfg={'access_key': config['AWS_ACCESS_KEY'],
										'secret_key': config['AWS_SECRET_KEY'], 
										'associate_tag': config['AWS_ASSOCIATE_TAG'],
										'locale': 'mx'})
Example #6
0
def amazonListSearch(query, num_results):
    from lxml import etree
    #API Access keys
    config = {
        'access_key': 'AKIAIKDCGPZIH4ZFFQGQ',
        'secret_key': 'MmVP8/U+zi3gZ23hQb88HgA/+DdA6PIF2mdQcO/9',
        'associate_tag': 'themanhproj-20',
        'locale': 'us'
    }
    #configuration of API
    api = amazonproduct.API(cfg=config)
    product_list = []
    try:
        #search for related items
        items = api.item_search('All', Keywords=query)
        Price = 0.00
        count = 0
        #product name, image url, features concatenated into a string

        try:
            #looks at first search result and lookups the price for it
            for stuff in items:
                #gets the ASIN number for the product
                ASIN = stuff.ASIN
                print ASIN
                asin_string = '%s' % (ASIN)
                imagesresult = api.item_lookup(asin_string,
                                               ResponseGroup='Images')
                newproduct = "hi"
                productname = '%s' % (stuff.ItemAttributes.Title)
                for item in imagesresult.Items.Item:
                    tempURL = item.LargeImage.URL
                    imageURL = '%s' % tempURL
                    break

                mediumresult = api.item_lookup(asin_string,
                                               ResponseGroup='Large')
                for item in mediumresult.Items.Item:
                    featurecount = 0
                    description = ''
                    for stuff in item.ItemAttributes.Feature:
                        converted_stuff = '%s' % (stuff)
                        description += converted_stuff + ', '
                        featurecount += 1
                        if featurecount == 4:
                            break
                if count == num_results:
                    break
                count += 1

                newproduct = (productname, imageURL, description)
                product_list.append(newproduct)
        except AttributeError:
            x = 0
    except NoExactMatchesFound:
        x = 0

    return product_list
def getCategoriesOfBooks(nodeid):
    api = amazonproduct.API(cfg=config)
    node_id = nodeid
    result = api.browse_node_lookup(node_id)
    list_of_child_nodes = []
    i = 0
    for child in result.BrowseNodes.BrowseNode.Children.BrowseNode:
        #print '%s (%s)' % (child.Name, child.BrowseNodeId)
        list_of_child_nodes.insert(i, child.BrowseNodeId)
        i += 1
    return list_of_child_nodes
def getGenreId_GenreName(nodeid):
    # Call with 1000 as input
    api = amazonproduct.API(cfg=config)
    node_id = nodeid
    result = api.browse_node_lookup(node_id)
    dict_of_child_nodes = {}
    i = 0
    for child in result.BrowseNodes.BrowseNode.Children.BrowseNode:
        #print '%s (%s)' % (child.Name, child.BrowseNodeId)
        dict_of_child_nodes[child.BrowseNodeId] = child.Name
        i += 1
    return dict_of_child_nodes
Example #9
0
def get_asin(product_type, keyword, associate_tag, callback=None):
    api = amazonproduct.API(AWS_KEY,
                            SECRET_KEY,
                            'us',
                            associate_tag=associate_tag)
    asin_list = []
    results = api.item_search(product_type,
                              Title=keyword,
                              IncludeReviewsSummary=True)
    for page in results:
        asin_list.extend([unicode(b.ASIN) for b in page.Items.Item])
        if results.current >= API_PAGE_LIMIT:
            break

    return asin_list
Example #10
0
def item_lookup(amazon_id):
    if not AMAZON_ACCESS_KEY:
        raise ConfigurationError("You must specify a valid AMAZON_ACCESS_KEY in project settings")
    if not AMAZON_SECRET_KEY:
        raise ConfigurationError("You must specify a valid AMAZON_SECRET_KEY in project settings")
    api = amazonproduct.API(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_LOCALE)
    kw = {'ResponseGroup': 'Medium'}
    if AMAZON_ASSOCIATE_TAG:
        kw['AssociateTag'] = AMAZON_ASSOCIATE_TAG
    try:
        return api.item_lookup(amazon_id, **kw).Items.Item[0]
    except InvalidParameterValue:
        raise Exception("Invalid amazon ID")
    except:
        raise
Example #11
0
def get_asin():
    azn_api = amazonproduct.API(locale='us')

    conn = sqlite3.connect('/media/ramdisk/example.db')
    c = conn.cursor()

    c.execute('SELECT id FROM ww_data')
    ids =  c.fetchall()
    for key_id in ids:
        c.execute('SELECT id, title FROM ww_data WHERE id= ?',
                  (key_id[0],))
        row = c.fetchone()
        DEBUG(ERR_TRACE, "get_azn: {}".format(
                row[1].encode('ascii', 'ignore')))

        try:
            results = azn_api.item_search(
                'Books',
                Title=row[1].encode('ascii', 'ignore'),
                Condition='New',
                Availability='Available',
                IncludeReviewsSummary='Yes')
        except amazonproduct.errors.NoExactMatchesFound:
            continue
        except amazonproduct.errors.AWSError:
            continue

        for item in results:
            if item.ASIN:
                # DEBUG(ERR_TRACE, "found ASIN={} for title'{}'".format(
                #     item.ASIN, item.ItemAttributes.Title))
                c.execute("""
UPDATE ww_data
  SET asin = ?, url_azn = ?
  WHERE id = ?
""", (str(item.ASIN), str(item.DetailPageURL), row[0])
                )
                conn.commit()
                break

    conn.commit()
    conn.close()
Example #12
0
 def get_results(job_title):
     api = amazonproduct.API(access_key_id=Amazon.ACCESS_KEY,
                             secret_access_key=Amazon.SECRET_KEY,
                             associate_tag=Amazon.ASSOCIATE_TAG,
                             locale='us')
     items = api.item_search('Books', Keywords=job_title)
     results = []
     for item in items:
         try:
             tite = item.ItemAttributes.Title
             tite = "Book"
             book_info = {
                 'author': item.ItemAttributes.Author,
                 'title': tite
             }
             results.append(book_info)
         #Some rows don't have the author or title attributes
         except AttributeError:
             pass
     return results
def getBooksFromAmazon():
    """
    :return: Dictionary of {genre_id: [(title, author, descr)...]
    Retrieve the book data from Amazon with the API
    """
    num_records = 300
    genre_dict = getGenreId_GenreName(1000)
    node_ids_genre = genre_dict.keys()
    #node_ids_genre = [25]
    books_dict = {}
    api = amazonproduct.API(cfg=config)
    for alphabet in node_ids_genre:
        print "Genre: " + str(alphabet)
        allbookscount = 0
        lst_tuple = []
        #Expand the data set to thousands
        #inner_children = getCategoriesOfBooks(alphabet)
        #for child in inner_children:
        time.sleep(1.2)
        items = api.item_search('Books', BrowseNode=alphabet,ResponseGroup="EditorialReview,ItemAttributes,BrowseNodes")
        tup = ()
        count = 0
        #if(len(items) < 3):
        #    continue
        for book in items:
            #print '%s' % book.EditorialReviews.EditorialReview.Content
            #print '%s: "%s"' % (book.ItemAttributes.Author,book.ItemAttributes.Title)
            try:
                tup = (book.ItemAttributes.Title, book.ItemAttributes.Author, blurb.utils.dehtml(book.EditorialReviews.EditorialReview.Content))
            except AttributeError:
                continue

            lst_tuple.insert(count, tup)
            count += 1
            allbookscount += 1
            if allbookscount >= num_records:
                break
        books_dict[alphabet] = lst_tuple
    return books_dict
Example #14
0
    def fetch(self):
        cnt = 0

        if not AMAZON_ACCESS_KEY or not AMAZON_SECRET_KEY:
            return cnt

        api = amazonproduct.API(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY,
                                AMAZON_LOCALE)

        kw = {'ResponseGroup': 'Medium'}
        kw['Keywords'] = self.keywords
        kw['AssociateTag'] = AMAZON_ASSOCIATE_TAG
        if self.browse_node:
            kw['BrowseNode'] = str(self.browse_node)
        response = api.item_search('Books', **kw)

        sites = list(self.sites.all())
        for item in response.Items.Item:
            amazon_id = item.ASIN
            try:
                Book.objects.get(amazon_id=amazon_id)
                continue
            except Book.DoesNotExist:
                pass
            try:
                data = get_book_data(item)
            except:
                continue
            book = Book(amazon_id=amazon_id)
            for field_name, value in data.items():
                if hasattr(book, field_name):
                    setattr(book, field_name, value)
            book.save()
            map(book.sites.add, sites)
            book.save()
            Category.objects.update_categories(book, self.categories)
            cnt += 1

        return cnt
Example #15
0
def search_amazon_products(static_folder, search_keywords):
    
    # Define constants 
    NUMBER_OF_ROWS_TO_RETURN = 10
    
    # Define variables
    all_products = []
    counter = 0
    
    # Create the path for the config file which stores credentials to the Amazon API 
    amazon_config_path = os.path.join(static_folder, 'config/amazon_config_file')
    
    # Instantiate the Amazon Product Advertising API
    api = amazonproduct.API(cfg=amazon_config_path)
    
    # Perform the search and get back the items from Amazon 
    products = api.item_search('All', Keywords = search_keywords, ResponseGroup='ItemAttributes, Images')
    
    # Loop through the products
    for curr_product in products: 
        
        # Define variables
        product_asin = product_mpn = product_title = product_manufacturer = product_brand = product_package_quantity = product_color = product_size = product_price = product_group = product_image = product_description = ''
   
        # Attempt to get all the details for the product
        try:
        
            # Get the product ASIN
            product_asin = str(curr_product.ASIN)

             # Print the status to the console - USED FOR DEBUGGING
             # print 'Product ASIN:' + product_asin

            # Get the remaining product attributes
            if hasattr(curr_product.ItemAttributes, 'Title'):
                product_title = repr(curr_product.ItemAttributes.Title)   
            if hasattr(curr_product.ItemAttributes, 'Manufacturer'):
                product_manufacturer = str(curr_product.ItemAttributes.Manufacturer)    
            if hasattr(curr_product.ItemAttributes, 'Brand'):
                product_brand = str(curr_product.ItemAttributes.Brand)
            if hasattr(curr_product.ItemAttributes, 'MPN'):
                product_mpn = str(curr_product.ItemAttributes.MPN)    
            if hasattr(curr_product.ItemAttributes, 'PackageQuantity'):          
                product_package_quantity =  str(curr_product.ItemAttributes.PackageQuantity)
            if hasattr(curr_product.ItemAttributes, 'Color'):     
                product_color =  str(curr_product.ItemAttributes.Color)
            if hasattr(curr_product.ItemAttributes, 'Size'):          
                product_size =  str(curr_product.ItemAttributes.Size) 
            if hasattr(curr_product.ItemAttributes, 'ListPrice'): 
                product_price = str(unicode(curr_product.ItemAttributes.ListPrice.FormattedPrice)).replace('$', '').strip()
            if hasattr(curr_product.ItemAttributes, 'ProductGroup'):         
                product_group = str(curr_product.ItemAttributes.ProductGroup)  
            if hasattr(curr_product.ImageSets.ImageSet, 'MediumImage'):         
                product_image = repr(unicode(curr_product.ImageSets.ImageSet.MediumImage.URL)).strip()
            if hasattr(curr_product.ItemAttributes, 'Feature'):         
                for feature in curr_product.ItemAttributes.Feature:
                    product_description = product_description + ' ' + repr(feature)
            product_description = product_description.strip()                          
            
            # Only return products with a price
            if (product_price != ''):
                
                # Only return the first 10 products as this is just a demo
                if (counter < NUMBER_OF_ROWS_TO_RETURN):

                    # Append to the current product attributes to the All Products Array
                    all_products.append({'product_asin': product_asin, 'product_mpn': product_mpn, 'product_title': product_title, 'product_manufacturer': product_manufacturer, 'product_brand': product_brand, 'product_package_quantity': product_package_quantity, 'product_color': product_color, 'product_size': product_size, 'product_price': product_price, 'product_group': product_group, 'product_image': product_image, 'product_description': product_description})

                    # Increment the counter
                    counter = counter + 1
            
        except Exception, ex:
            
            # Print the error message 
            print  '    Skipping this product - ' + str(ex)
import re
import amazonproduct
import sys, os

modpath = os.path.join(request.folder, 'modules')
if not modpath in sys.path:
    sys.path.append(modpath)
import lmsconfig

cfg = lmsconfig.getcfg(modpath)

if cfg.aws_enable:
    _aws_ns = {
        'aws': 'http://webservices.amazon.com/AWSECommerceService/2009-10-01'
    }
    _aws_api = amazonproduct.API(cfg.aws_id, cfg.aws_key, locale='us')


def book_search(kwds):
    if cfg.aws_enable:
        if len(kwds):
            terms = []
            for k in kwds:
                terms.append(k + ':' + kwds[k])
                pwrsrch = ' and '.join(terms)
                nodes = _aws_api.item_search('Books',
                                             ResponseGroup='ItemAttributes',
                                             Power=pwrsrch)
                books = []
            for book in nodes.xpath('//aws:Items/aws:Item',
                                    namespaces=_aws_ns):
Example #17
0
from categories.models import Category
import amazonproduct
import lxml

api = amazonproduct.API(cfg=config)

root_categories = [('Clothing, Shoes, Jewelry and Watches', 7141123011),
                   ('Android Apps', 2350149011), ('Books', 283155),
                   ('Kindle Store', 133140011),
                   ('Magazine Subscriptions', 599858),
                   ('Movies & TV', 2625373011), ('CD and Vinyl', 5174),
                   ('Digital Music', 163856011), ('Video Games', 468642),
                   ('Electronics', 172282),
                   ('Cell Phones & Accessories', 2335752011),
                   ('Appliances', 2619525011), ('Software', 229534),
                   ('Musical Instruments', 11091801),
                   ('Office and School Supplies', 1064954),
                   ('Home & Kitchen', 1055398),
                   ('Patio, Lawn & Garden', 2972638011),
                   ('Tools & Home Improvement', 228013),
                   ('Arts and Sewing', 2617941011),
                   ('Pet Supplies', 2619533011),
                   ('Grocery & Gourmet Food', 16310101),
                   ('Health, Household & Baby Care', 3760901),
                   ('Beauty', 3760911), ('Toys & Games', 165793011),
                   ('Baby', 165796011), ('Sports & Outdoors', 3375251),
                   ('Automotive Parts & Accessories', 15684181),
                   ('Business, Industrial & Scientific Supplies', 16310091)]

count = 0
import os
from xml.etree import ElementTree

import amazonproduct

AMAZON_ACCESS_KEY = os.environ['AMAZON_ACCESS_KEY']
AMAZON_SECRET_KEY = os.environ['AMAZON_SECRET_KEY']
AMAZON_ASSOCIATE_TAG = os.environ['AMAZON_ASSOCIATE_TAG']

api = amazonproduct.API(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, 'jp',
                        AMAZON_ASSOCIATE_TAG)

response = api.item_search('All', Keywords='kindle', ResponseGroup='Large')
print(response)

for item in response.Items.Item:
    print(item.ItemAttributes.Title, item.ItemAttributes.FormattedPrice)
Example #19
0
def azonPriceGrab(responsee=None, asin=None):
    import amazonproduct
    config = {
        'access_key': '###',
        'secret_key': '###',
        'associate_tag': '###',
        'locale': 'us'
    }
    api = amazonproduct.API(cfg=config)

    try:
        # ##Call if p is an asin
        # if isinstance(p, str):
        #     response = api.item_lookup(p, ResponseGroup='Offers', Condition='New')
        #     asin = p
        # else:
        #     response = p
        #     asin = response.Items.Item.ASIN.text
        if responsee is not None:
            response = responsee
            asin = response.ASIN.text
        elif asin is not None:
            response = api.item_lookup(asin,
                                       ResponseGroup='Offers',
                                       Condition='New')
            response = response.Items.Item
            asin = asin

        tree = response.Offers.Offer.OfferListing
        avail = response.Offers.Offer.OfferListing.AvailabilityAttributes.AvailabilityType.text
        availMinHours = response.Offers.Offer.OfferListing.AvailabilityAttributes.MinimumHours.text
        prime = response.Offers.Offer.OfferListing.IsEligibleForPrime.text
        if prime == '1' and avail == 'now':
            if int(availMinHours) > 48:
                # print 'More than 2 days to ship... Returning false'
                # print 'Min Hours:' + availMinHours
                return False
            price = getattr(tree, 'SalePrice', None)
            if price is not None:
                price = (response.Offers.Offer.OfferListing.SalePrice.
                         FormattedPrice.text)
            else:
                price = (response.Offers.Offer.OfferListing.Price.
                         FormattedPrice.text)
            price = (price)[1:]
            return float(price)
        else:
            # print("First check no go. " + " Prime: " + prime + " Avail: " + avail)
            # print("Checking sold by Amazon...")
            #time.sleep(1)
            response = api.item_lookup(asin,
                                       ResponseGroup='Offers',
                                       MerchantId='Amazon',
                                       Condition='New')
            tree = response.Items.Item.Offers.Offer.OfferListing
            avail = response.Items.Item.Offers.Offer.OfferListing.AvailabilityAttributes.AvailabilityType.text
            availMinHours = response.Items.Item.Offers.Offer.OfferListing.AvailabilityAttributes.MinimumHours.text
            #print 'Min Hours:' + availMinHours
            #prime = response.Items.Item.Offers.Offer.OfferListing.IsEligibleForPrime.text
            #if prime == '1' and avail == 'now':
            if avail == 'now':
                if int(availMinHours) > 48:
                    #print 'More than 2 days to ship... Returning false'
                    return False

                price = getattr(tree, 'SalePrice', None)
                if price is not None:
                    price = response.Items.Item.Offers.Offer.OfferListing.SalePrice.FormattedPrice.text
                else:
                    price = response.Items.Item.Offers.Offer.OfferListing.Price.FormattedPrice.text
                price = (price)[1:]
                return float(price)
            #print("Second check no go" + " Prime: " + prime + " Avail: " + avail)

        #return runAzonScraper(productURL)

        #print("Can't find any price... Setting price and quant to 0")
        #setStockQuant(opts,ebayProductID,0)
        return False
    except AttributeError as e:
        #return runAzonScraper(productURL)
        #print("Can't find price for this item...")
        #print("Setting price to 300 and quant to 0")
        #setStockQuant(opts,ebayProductID,0)
        return False
Example #20
0
import amazonproduct

#CREATE CREDENTIAL FILE
# .amazon-product-api in home directory
# [Credentials]
#access_key = <your access key>
#secret_key = <your secret key>
#associate_tag = <your associate id>

api = amazonproduct.API(locale='us')


def searchItem(key):
    items = api.item_search('All',
                            Keywords=key,
                            ResponseGroup='ItemIds,ItemAttributes,Reviews')
    return items


def getProductURLArray(key):
    dict = {}
    items = searchItem(key)
    for item in items:
        dict[item.ASIN] = item.DetailPageURL
    return dict
Example #21
0
 def find_by_asin(self, asin):
     api = amazonproduct.API(locale='jp')
     result = api.item_lookup(asin)
     for i, elem in enumerate(result.Items.Item):
         return self.to_dict(elem, i)
 def __init__(self):
     self.config_parser = ConfigParser.RawConfigParser()
     self.config_parser.read('configuration.ini')
     self.amazon_api = amazonproduct.API(locale='de')
Example #23
0
 def __init__(self):
     self.api = amazonproduct.API(cfg=AMAZON_CONFIG)
     self.associate_tag = AMAZON_CONFIG['associate_tag']
Example #24
0
import amazonproduct, os


aws_api = amazonproduct.API(cfg={
    'access_key': os.getenv('AWS_ACCESS_KEY_ID'),
    'secret_key': os.getenv('AWS_SECRET_ACCESS_KEY'),
    'associate_tag': os.getenv('AWS_ASSOCIATE_TAG'),
    'locale': os.getenv('AWS_LOCALE')
})


from pprint import pprint

class Amazon:

	@staticmethod
	def search(keywords):
		products = []
		#limit to 5, get reviews of each and return them
		items = aws_api.item_search('All', Keywords=keywords)

		limit = len(items) if len(items) < 5 else 5
		count = 0
		for item in items:
			if count >= limit:
				break
			#print '%s: "%s"' % (book.ItemAttributes.Author, book.ItemAttributes.Title)
			products.append(item)
			product_id = item.ASIN
			#product = aws_api.item_lookup(str(product_id), ResponseGroup='Reviews', IncludeReviewsSummary=True)[0]
			count += 1

# In[load_data]
# file name, located in the working directory
file_name = "products_reviewed.csv"

# use pandas to read in the data
products = pd.read_csv(file_name, nrows=5)


# In[remove_string] 
'''
replace the "remove after loading" string ...
the string below, rm_str is in place just to be extra cautious about ...
leading zeros in the product id. So, to preserve the string format across ...
platforms, I include a string to remove upon loading
'''
rm_str = "remove after loading"
products['product_id'] = products['product_id'].replace(rm_str, "", regex=True)


# In[api_call]
# define api
from lxml import etree
api = amazonproduct.API(locale="us")

# submit a request
results = api.item_lookup("B012A8DUVK", ResponseGroup="ItemAttributes,SalesRank")
print etree.tostring(results, pretty_print=True) # just a string 

Example #26
0
 def __init__(self):
   # Get the keys from gconf, or some secret location
   self.api = amazonproduct.API(locale='uk')