class GiftlyAmazonAPI: amazon_product_details = ['api', 'asin', 'author', 'authors', 'aws_associate_tag', 'binding', 'brand', 'browse_nodes', 'color', 'creators', 'ean', 'edition', 'editorial_review', 'editorial_reviews', 'eisbn', 'features', 'get_attribute', 'get_attribute_details', 'get_attributes', 'get_parent', 'images', 'isbn', 'label', 'languages', 'large_image_url', 'list_price', 'manufacturer', 'medium_image_url', 'model', 'mpn', 'offer_url', 'pages', 'parent', 'parent_asin', 'parsed_response', 'part_number', 'price_and_currency', 'publication_date', 'publisher', 'region', 'release_date', 'reviews', 'sales_rank', 'sku', 'small_image_url', 'tiny_image_url', 'title', 'to_string', 'upc'] amazon_search_index = ['All','Apparel','Appliances','ArtsAndCrafts','Automotive', 'Baby', 'Beauty','Blended','Books','Classical','Collectibles','DVD', 'DigitalMusic','Electronics', 'GiftCards','GourmetFood','Grocery', 'HealthPersonalCare','HomeGarden','Industrial','Jewelry', 'KindleStore', 'Kitchen','LawnAndGarden','Marketplace','MP3Downloads','Magazines','Miscellaneous', 'Music','MusicTracks','MusicalInstruments','MobileApps','OfficeProducts','OutdoorLiving', 'PCHardware', 'PetSupplies','Photo','Shoes','Software','SportingGoods', 'Tools','Toys','UnboxVideo','VHS','Video', 'VideoGames','Watches','Wireless','WirelessAccessories'] def __init__(self, secret_key, access_key, assoc_tag): self.amazon = AmazonAPI(access_key, secret_key, assoc_tag) #Keywords is a comma-separated string #Returns a dictionary of products mapped as ASIN:TITLE #Can Android parse for keys? We'll find out... def get_similar_items(self, keywords, numitems=None, category=None): keywords = keywords if keywords else None numitems = numitems if numitems else 10 category = category if category else 'All' print "%d items found with keywords %s in the %s category" % (numitems, keywords, category) products = self.amazon.search_n(numitems, Keywords=keywords, SearchIndex=category) product_dict = {} for product in products: product_dict[product.asin] = product.title return product_dict def get_item_by_asin(self, asin): product = self.amazon.lookup(ItemId=asin) product = AmazonProduct(product.asin, product.title) return product.get_product() #asin_list is a list of individual asin strings #they are joined together as one large string def get_items_by_asin(self, asin_list): product_list = [] products = self.amazon.lookup(ItemId=(asin_list)) for product in products: product_list.append(AmazonProduct(product.asin, product.title).get_product()) print product_list return product_list
class AmazonBaseCrawler(object): region = 'US' max_batch_lookup = 10 def __init__(self): self.amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG, region=self.region) def parse_product(self, product): price_and_currency = product.price_and_currency price = price_and_currency[0] currency = price_and_currency[1] if currency == 'JPY': price = float(price) * 100 print(self.region, product.asin, price, currency, product.title) return { 'shop_product_id': product.asin, 'price': price, 'currency': currency, 'title': product.title, } def fetch_batch(self, product_ids): result = [] for chunk_product_ids in chunks(product_ids, self.max_batch_lookup): try: products = self.amazon.lookup( ItemId=','.join(chunk_product_ids)) except urllib2.HTTPError: return result try: for product in products: result.append(self.parse_product(product)) except TypeError: result.append(self.parse_product(products)) sleep(1) return result def fetch_from_id(self, product_id): product = self.amazon.lookup(ItemId=product_id) price_and_currency = product.price_and_currency amiibo_price = { 'shop_product_id': product_id, 'price': price_and_currency[0].replace(',', ''), 'currency': price_and_currency[1], } return amiibo_price
def handle(self, *args, **options): amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG) two_days_ago = date.today() - timedelta(days=2) # isbns = [book.isbn for book in Book.objects.filter(mod_date__gte=two_days_ago)] isbns = [book.isbn for book in Book.objects.all()] grouped_isbns = map(None, *[iter(isbns)]*10) print "=== Start daily book update." for index, isbns in enumerate(grouped_isbns): isbns = filter(None, isbns) isbns = ",".join(isbns) print " == index : %s / items : %s" % (str(index), isbns) amazon_books = amazon.lookup(ItemId=isbns) for amazon_book in amazon_books: try: dbbook = Book.objects.get(isbn__exact=amazon_book.isbn) dbbook.update(amazon_book) except Book.DoesNotExist: Book.objects.create_book(amazon_book) time.sleep(4) print "=== Successful updated all books"
class AmazonProductProxy: def __init__(self, force_own_api=False): self.root = os.path.join(app.config['APP_ROOT'], "amws") self.profile = app.config['PROFILE'] aws_list_cred = self.get_aws_cred_from_file() if force_own_api: self.amazon = AmazonAPI(*aws_list_cred, Region='ES') else: if self.profile == BaseConfig.DEVELOPMENT_PROFILE: self.amazon = AmazonAPI(*aws_list_cred, Region='ES') else: self.amazon = ProductionAmazonAPI(*aws_list_cred, Region='ES') def search_products(self, query): product_res = self.extract_products( self.amazon.search(Keywords=query, SearchIndex='All', Availability="Available")) return product_res def search_by_asin(self, asin_list): return self.extract_products(self.amazon.lookup(ItemId=",".join(asin_list))) def create_cart(self, offer_id, quantity=1): item_dict = {'offer_id': offer_id, 'quantity': quantity} return self.amazon.cart_create(item_dict) def extract_products(self, products): product_res = [] try: for i, product in enumerate(products): # print "{0}. '{1}'".format(i, product.title) product_res.append(product) except Exception, e: return product_res return product_res
def amazon_api(asin, url, marketplace = 'US', retries=0): try: if (retries < 2): amazon = AmazonAPI(settings.AWS_KEY_1, settings.AWS_SECRET_1, settings.AWS_API_1, region=marketplace) if (retries >= 2 and retries < 4): amazon = AmazonAPI(settings.AWS_KEY_2, settings.AWS_SECRET_2, settings.AWS_API_2, region=marketplace) if (retries >= 4 and retries < 6): amazon = AmazonAPI(settings.AWS_KEY_3, settings.AWS_SECRET_3, settings.AWS_API_3, region=marketplace) if (retries >= 6 and retries < 8): amazon = AmazonAPI(settings.AWS_KEY_3, settings.AWS_SECRET_3, settings.AWS_API_4, region=marketplace) if (retries >= 8 and retries < 10): amazon = AmazonAPI(settings.AWS_KEY_3, settings.AWS_SECRET_3, settings.AWS_API_5, region=marketplace) product = amazon.lookup(ItemId=asin) model_product = ProductRecord( title=product.title, product_url='<missing product url>', listing_url=url, price=str(product.price_and_currency[1])+str(product.price_and_currency[0]), primary_img=product.large_image_url, product_indexing=None, crawl_time=datetime.now(), asin=asin.upper() ) if (product.asin != asin): return None return model_product except Exception as e: if (retries <= 10): return amazon_api(asin, url, marketplace, retries+1) return None
def update_product(product): url = product.product_url AMAZON_ACCESS_KEY = 'AKIAIZPHCO56EZACZHBA' AMAZON_SECRET_KEY = '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' AMAZON_ASSOC_TAG = '1015f-21' region = url.split("amazon.")[1].split("/")[0] if "/dp/" in url: ASIN = url.split("/dp/")[1].strip("/").split("/")[0] elif "/gp/" in url: ASIN = url.split("/gp/product/")[1].strip("/").split("/")[0] print(ASIN) amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region=region.upper()) products = amazon.lookup(ItemId=ASIN) price, currency = products.price_and_currency graph = Graph(product_id=product, updated_at=datetime.now(), current_price=price) graph.save() return
class AmazonScraper(object): def __init__(self, access_key, secret_key, associate_tag, *args, **kwargs): self.api = AmazonAPI(access_key, secret_key, associate_tag, *args, **kwargs) def reviews(self, ItemId=None, URL=None): return Reviews(self, ItemId, URL) def review(self, Id=None, URL=None): return Review(self, Id, URL) def lookup(self, URL=None, **kwargs): if URL: kwargs['ItemId'] = extract_asin(URL) result = self.api.lookup(**kwargs) if isinstance(result, (list, tuple)): result = [Product(p) for p in result] else: result = Product(result) return result def similarity_lookup(self, **kwargs): for p in self.api.similarity_lookup(**kwargs): yield Product(p) def browse_node_lookup(self, **kwargs): return self.api.browse_node_lookup(**kwargs) def search(self, **kwargs): for p in self.api.search(**kwargs): yield Product(p) def search_n(self, n, **kwargs): for p in self.api.search_n(n, **kwargs): yield Product(p)
def asin_image(self): amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG) try: product = amazon.lookup(ItemId=self.asin) return product.large_image_url except: return None
def update_price(self): # check if this is an Amazon product if self.distributor.name == 'Amazon': amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG) try: product = amazon.lookup(ItemId=self.part.asin) price = product.price_and_currency return price[0] except: pass else: import urllib2 from lxml import etree import microdata import urllib items = microdata.get_items(urllib.urlopen(self.url)) for i in items: if i.offers: return "%s (md)".replace("$", "") % i.offers.price.strip().replace("$", "") html = urllib2.urlopen(self.url).read() tree = etree.HTML(html) price = tree.xpath("%s/text()[1]" % self.xpath) try: return "%s (xp)" % price[0].replace("$", "") except: return "N/A"
class Item(object): def __init__(self, product): self.product = product self.amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) def prod_search(self): products_found = self.amazon.search_n(1, Keywords= self.product, SearchIndex= "All") return products_found def prod_item(self): products_found = self.prod_search() try: return products_found[0].title except IndexError: raise Exception('No product found') def prod_asin(self): products_found = self.prod_search() try: return products_found[0].asin except IndexError: raise Exception('No Asin found') def prod_price(self): product_asin = self.prod_asin() the_product = self.amazon.lookup(ItemId='' + product_asin + '') found_product_price = the_product.price_and_currency print the_product.image return found_product_price
def amazonResults(amazonID): '''Puts ASIN through Amazon API and returns item title, price, and image''' amazon = AmazonAPI(amazonAccessKey, amazonSecretKey, amazonAssocTag) product = amazon.lookup(ItemId=amazonID) title = product.title image = product.large_image_url price = product.price_and_currency return title, price, image
def amazon_price(self): amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG) try: product = amazon.lookup(ItemId=self.asin) price = product.price_and_currency return "$%.2f %s" % (price[0], price[1]) except: return None
def add_book(request, isbn): amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG) amazon_book = amazon.lookup(ItemId=isbn) Book.objects.create_book(amazon_book) if request.is_ajax(): return HttpResponse(status=200) else: return HttpResponseRedirect(request.META.get("HTTP_REFERER", ""))
def crawl_movie(id): amazon = AmazonAPI("AKIAILGCGSOAJBIYFIQA", "xz53Hn0stSpZ2LpqRejomhnZflsqNt/Yhq58VOAK", "ericpan2018-20") movie = amazon.lookup(ItemId=id) with open('/home/eric/Data/poster/' + id + '.jpg', 'wb') as f: f.write(requests.get(movie.large_image_url).content) print(movie.title) return movie.title
def get(self): amazon = AmazonAPI() watches = models.get_db_watches() if watches: for WatchListing in watches: product = amazon.lookup(ItemId=WatchListing.ItemId) WatchListing.Price = product.price_and_currency[0] WatchListing.put() time.sleep(1) #amazon only allows a single API per second... return
def add_to_cart(request, cartItems): amazon = AmazonAPI('Access Key', 'Secret Key', 'gs2671-20') flag = True cartItems = eval(cartItems) for item in cartItems: if (flag): product = amazon.lookup(ItemId=item) amazon_cart = amazon.cart_create([{ 'offer_id': product.offer_id, 'quantity': 1 }]) flag = False else: product = amazon.lookup(ItemId=item) amazon.cart_add({ 'offer_id': product.offer_id, 'quantity': 1 }, amazon_cart.cart_id, amazon_cart.hmac) return HttpResponseRedirect(amazon_cart.purchase_url)
def retrieve_amazon_data(id='00000000000', type=TYPE): amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) try: product = amazon.lookup(ItemId=id, IdType=type, SearchIndex='Books') except: return None try: return product.isbn except AttributeError: # So probably not a book then? return None
def prod_price(self, product_asin): #insert amazon web services credentials AMAZON_ACCESS_KEY = 'AKIAJGEKFL3UEU6QMCPQ' AMAZON_SECRET_KEY = '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' #associate TAG must be updated every 180 days, make new amazon associates account to get new tag AMAZON_ASSOC_TAG = 'ignacio0ba-20' amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) the_product = amazon.lookup(ItemId='' + product_asin + '') found_product_price = the_product.price_and_currency
class AmazonController: def __init__(self): keys = Amazon.objects.all() key = keys[0] self.amazon = AmazonAPI(key.access_key.encode('ascii'), key.secret_key.encode('ascii'), key.assoc_tag.encode('ascii')) def lookup(self, item_id, id_type = 'ASIN', search_index = ''): try: response = self.amazon.lookup(ItemId = item_id, IdType = id_type, SearchIndex = search_index) return response except: return None
def amazon_plugin(sender, **kwargs): description1 = kwargs['instance'].description.split("delimiter") e = [] for m in re.finditer('code:\[', kwargs['instance'].description): e.append(kwargs['instance'].description[m.end() + 5:m.end() + 15]) for i in e: key = (kwargs['instance'].description.find(i)) print(key) amazon1 = AmazonAPI(Access_Key, Secret_Key, Tag) product = amazon1.lookup(ItemId=i) description1 = (listToString(description1).replace( kwargs['instance'].description[key - 11:key + 16], ("<a target='__blank' href=" + product.detail_page_url + "><img src=" + product.large_image_url + "></a>"))) kwargs['instance'].description = description1
def fetch_from_amazon(game): title = ''.join(('NES ', game.title)) AMAZON_ACCESS = os.environ['AMAZON_ACCESS'] AMAZON_SECRET = os.environ['AMAZON_SECRET'] AMAZON_AWS = os.environ['AMAZON_AWS'] amazon = AmazonAPI(AMAZON_ACCESS, AMAZON_SECRET,AMAZON_AWS) try: products = amazon.search_n(1, Keywords=title, Condition='Used', SearchIndex = 'VideoGames') return amazon.lookup(ItemId=products[0].asin, Condition='Used') # if above fails the template handles the error except: pass
def createCart(products): pdict = {} for item in products: if item in pdict: pdict[item] = pdict[item] + 1 else: pdict[item] = 1 amazon = AmazonAPI(ACCESS_KEY, SECRET_KEY, ASSOC_ID) for index, key in enumerate(pdict.items()): product = amazon.lookup(ItemId=key[0]) item = {'offer_id': product.offer_id, 'quantity': key[1]} if index == 0: cart = amazon.cart_create(item) else: cart = amazon.cart_add(item, cart.cart_id, cart.hmac) return cart
def get_amazon_book_data(cls, isbn): amazon = AmazonAPI(os.environ['AWS_ACCESS_KEY_ID'], os.environ['AWS_SECRET_ACCESS_KEY'], os.environ['AWS_ASSOCIATE_TAG'], region='UK') product_or_products = amazon.lookup(ItemId=isbn, IdType='ISBN', SearchIndex="Books") if type(product_or_products) is list: product = product_or_products[0] else: product = product_or_products return {'isbn': isbn, 'title': product.title, 'page_count': product.pages, 'authors': product.authors }
def get_amazon_product_meta(url): # the input URL is always of amazon amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="IN") item_id = get_amazon_item_id(url) if not item_id: return None try: product = amazon.lookup(ItemId=item_id) except amazon.api.AsinNotFound: # log this ASIN return None # product.price_and_currency returns in the form (price, currency) product_price = product.price_and_currency[0]
class AmazonController: def __init__(self): keys = Amazon.objects.all() key = keys[0] self.amazon = AmazonAPI(key.access_key.encode('ascii'), key.secret_key.encode('ascii'), key.assoc_tag.encode('ascii')) def lookup(self, item_id, id_type='ASIN', search_index=''): try: response = self.amazon.lookup(ItemId=item_id, IdType=id_type, SearchIndex=search_index) return response except: return None
class AmazonApi(SpidersToolBox, AmazonAPI): def __init__(self): super(AmazonApi, self).__init__() self.responsegroup = "Images,ItemAttributes,Offers" self.amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="CN", ErrorHandler=self.error_handler) self.sql = """ select stcode from crawl.amazon_base_information201907 where barcode=%s; """ # and stock is not false and crawl_state != 3 def error_handler(self, error): ex = error['exception'] if ex.code == 503: time.sleep(1) return True def func1(self, stcode): url = "https://www.amazon.cn/dp/{}".format(stcode) response = requests.get(url, headers={"User-Agent": self.user_agent}) # html_data = etree.HTML(response.content.decode()) with open("sss.html", "w", encoding="utf-8") as f: f.write(response.text) def func2(self, stcode): try: products = self.amazon.lookup(IdType="ASIN", ItemId=stcode, ResponseGroup=self.responsegroup) a, b = products.price_and_currency except Exception as e: self.logger.debug(e) else: print(a) print(b) def main(self, barcode): sql = self.sql self.conn.execute(sql, (barcode, )) res = self.conn.fetchone() self.func1(res[0])
def single_access(self, token, option=None): Wrapper.single_access(self,token) result = {} try: asin = option['item'] amazon = AmazonAPI(token['ACCESS_KEY'], token['SECRET_KEY'], token['ASSOC_TAG'], region=token['LOCALE']) data = amazon.lookup(ItemId=asin) result['raw'] = data result['title'] = data.title result['category'] = data.get_attribute('ProductGroup') except: # If any exceptions happen, return None sys.stderr.write("Unexpected error accessing API:\n\t%s\n\t%s" % (sys.exc_info()[0], sys.exc_info()[1])) result = None return result
def update_price(): time_threshold = timezone.now() - timedelta(minutes=settings.UPDATE_PRICE_THRESHOLD) affiliate = Affiliate.objects.get(name='Amazon') products = Product.objects.filter(price_updated__lt=time_threshold, affiliate=affiliate).order_by('price_updated')[:10] if len(products) > 0: asins = [p.asin for p in products] asins_string = ','.join(asins) amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG) az = amazon.lookup(ItemId=asins_string) if type(az) is list: for p in az: process_item(p) else: process_item(az)
class SalesRankFetchService(): def __init__(self, log): self.log = log self.api_amazon_de = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="DE") def get_all_salesranks(self): """ Use the amazon product API to receive the salesrank and the price for each of our products. Because the service is not always responding deterministic we will try in case of error for six times to get the corresponding value. At usual the second try is getting a result. """ number_of_fetched_salesrank = 0 products = Product.objects.all() for product in products: item = None self.log.info('Lookup: {}'.format(product.asin)) for period in WAIT_PERIODS_IN_SECONDS: try: item = self.api_amazon_de.lookup(ItemId=product.asin) break except HTTPError: self.log.info('Error occured, wait no for: {} seconds'.format(period)) time.sleep(period) if item and item.sales_rank: self.log.info(' Got salesrank: {}'.format(item.sales_rank)) self.log.info(' Got price: {}'.format(item.price_and_currency[0])) price = item.price_and_currency[0] if price: salesrank_history_entry = SalesRankHistory( product=product, price=price, salesrank=item.sales_rank) salesrank_history_entry.save() number_of_fetched_salesrank += 1 self.log.info('Number of fetched salesrank: {}'.format(number_of_fetched_salesrank))
def handle(self, *args, **options): products = Product.objects.all().order_by('-created') amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG) for p in products: print "Fetching %s..." % p.asin try: az = amazon.lookup(ItemId=p.asin) lf, file_ext = amazon_utils.fetch_image(az.large_image_url) large_image = amazon_utils.fit_image(lf, (699, 875)) thumb = amazon_utils.fit_image(lf, (285, 340), margin=100) p.image.save("%s-large.%s" % (p.product_id, file_ext), files.File(large_image)) p.thumb.save("%s-small.%s" % (p.product_id, file_ext), files.File(thumb)) except: print 'failed' time.sleep(1)
def get_products(self, obj): ''' Gets the products attached to the order. The expand method is provided here because we won't always want to query Amazon for specific information about the product. If expand is true we will hit Amazon and get back specific information about the product such as price and images. :param obj: :return: ''' request, expand, _, _, _ = gather_request_data(self.context) serialized_products = [ ProductSerializer(product).data for product in obj.get_products() ] if expand == 'true': # pragma: no cover # Not covering this as we have no good way to mock a request to # the amazon api as they use request signatures. - Devon Bleibtrey vendor_ids = [ product['vendor_id'] for product in serialized_products ] amazon = AmazonAPI(settings.AMAZON_PROMOTION_API_KEY, settings.AMAZON_PROMOTION_API_SECRET_KEY, settings.AMAZON_ASSOCIATE_TAG) for sub_list in chunk_list(vendor_ids, 10): sub_ids = ",".join(sub_list) products = amazon.lookup(ItemId=sub_ids) if not hasattr(products, '__iter__'): products = [products] for product in products: match = next((l for l in serialized_products if l['vendor_id'] == product.asin), None) if match is not None: price, currency = product.price_and_currency match['information'] = { "title": product.title, "image": product.large_image_url, "price": price, "currency": currency, "asin": product.asin, "url": product.offer_url } return serialized_products
def handle(self, *args, **options): amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG) # yesterday = date.today() - timedelta(days=1) # isbns = [book.isbn for book in Book.objects.filter(mod_date__gte=yesterday)] isbns = [book.isbn for book in Book.objects.all()] grouped_isbns = map(None, *[iter(isbns)]*10) print "=== Start daily rank update." for index, isbns in enumerate(grouped_isbns): time.sleep(4) isbns = filter(None, isbns) isbns = ",".join(isbns) print " == index : %s / items : %s" % (str(index), isbns) books = amazon.lookup(ItemId=isbns) for item in books: if item.item.__dict__.get('SalesRank') is None: continue dbbook = Book.objects.get(isbn__exact=item.isbn) try: r = Rank.objects.get(date=datetime.date.today(), book=dbbook) continue except: pass print " = daily rank added for %s" % dbbook r = Rank.objects.create( date=datetime.date.today(), book=dbbook, rank=item.item.SalesRank ) from django.contrib.auth.models import User # streams = User.objects.get(username='******') ranked_streams = User.objects.get(username='******') action.send(dbbook, verb='new rank is %s\'' % r.rank, action_object=ranked_streams, target=r) print "=== Successful updated all ranks"
def amazon_api(asin, url, marketplace='US'): try: amazon = AmazonAPI(settings.AWS_KEY, settings.AWS_SECRET, settings.AWS_API, region=marketplace) product = amazon.lookup(ItemId=asin) model_product = ProductRecord( title=product.title, product_url='<missing product url>', listing_url=url, price=str(product.price_and_currency[1]) + str(product.price_and_currency[0]), primary_img=product.large_image_url, product_indexing=None, crawl_time=datetime.now(), asin=asin.upper()) return model_product except: return None
def save(self, *args, **kwargs): #is_new = self.id < 1 is_new = True super(Book, self).save(*args, **kwargs) if not is_new: return amazon = AmazonAPI( settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG) books = amazon.lookup( IdType='ISBN', ItemId=self.isbn, SearchIndex='All') if books: if isinstance(books, list): book = books[0] else: book = books Book.objects.filter(pk=self.pk).update( title=book.title, author=', '.join(book.authors), image_url=book.large_image_url)
def getAmazonProductMeta(books,book): #finds the prices of a given book in the dict of books, and updates the book with a new dictionary entry, in the format of date:smartPrice. amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) item_id = books[book]["id"] try: product = amazon.lookup(ItemId=item_id) except amazon.api.AsinNotFound: # log this ASIN return None except Exception: return None newPrice = product._safe_get_element_text("OfferSummary.LowestNewPrice.FormattedPrice") usedPrice = product._safe_get_element_text("OfferSummary.LowestUsedPrice.FormattedPrice") tradeInPrice = product._safe_get_element_text("ItemAttributes.TradeInValue.FormattedPrice") if newPrice or usedPrice or tradeInPrice: books[book][str(date.today())] = smartPrice(newPrice, usedPrice, tradeInPrice)
def amazon_textbook_fields(isbn): if amazon is None: amazon = AmazonAPI(get_secret('AMAZON_ACCESS_KEY'), get_secret('AMAZON_SECRET_KEY'), get_secret('AMAZON_ASSOC_TAG')) try: product = amazon.lookup(ItemId=isbn, IdType='ISBN', SearchIndex='Books') except AsinNotFound: return if isinstance(product, list): product = product[0] return { 'detail_url': product.detail_page_url, 'image_url': product.medium_image_url, 'author': product.author, 'title': product.title, }
def single_access(self, token, option=None): Wrapper.single_access(self, token) result = {} try: asin = option['item'] amazon = AmazonAPI(token['ACCESS_KEY'], token['SECRET_KEY'], token['ASSOC_TAG'], region=token['LOCALE']) data = amazon.lookup(ItemId=asin) result['raw'] = data result['title'] = data.title result['category'] = data.get_attribute('ProductGroup') except: # If any exceptions happen, return None sys.stderr.write("Unexpected error accessing API:\n\t%s\n\t%s" % (sys.exc_info()[0], sys.exc_info()[1])) result = None return result
def get_amazon_image(self): amazon = AmazonAPI(os.environ['AWS_ACCESS_KEY_ID'], os.environ['AWS_SECRET_ACCESS_KEY'], os.environ['AWS_ASSOCIATE_TAG'], region='UK') try: product = amazon.lookup(ItemId=self.isbn, IdType='ISBN', SearchIndex="Books") if type(product) is list: for prod in product: if prod.large_image_url: self.image_url = prod.large_image_url elif prod.medium_image_url: self.image_url = prod.medium_image_url elif product.large_image_url: self.image_url = product.large_image_url elif product.medium_image_url: self.image_url = product.medium_image_url except AsinNotFound: self.image_url = "/static/images/unknown.png" self.save()
class Product_API: def __init__(self, aws_access_key, aws_secret_key, associate_tag, region): self.aws_access_key = aws_access_key self.aws_secret_key = aws_secret_key self.associate_tag = associate_tag self.amazon = AmazonAPI(self.aws_access_key, self.aws_secret_key, self.associate_tag, region=region) def formate_string(self, string): return '' if string is None else str(string) def formate_content(self, content): return content.replace('"', '').replace('\t', '').replace( '\n', '') if content else '' def get_upc_details(self, productid): data = {} try: products = self.amazon.lookup(ItemId=productid, IdType='UPC', SearchIndex='All') try: #print('changdu',len(products)) #print(productid) for i in range(len(products)): asin = products[i].asin upc = products[i].upc data[upc] = True for upc in productid.split(','): data[upc] = True except: pass except AsinNotFound: pass except HTTPError: time.sleep(0.5) self.get_product_details(productid) return data
class AmazonCrawler(MerchantCrawler): def __init__(self, creds): super(AmazonCrawler, self).__init__() self.ep = AmazonAPI(creds.get("AWS_ACCESS"), creds.get("AWS_SEC_KEY"), creds.get("AMAZON_ASSOC_TAG")) regex = "http://www.amazon.com/([\\w-]+/)?(dp|gp/product)/(\\w+/)?(\\w{10})" self.rc = re.compile(regex) def crawl_url(self, url): urlgrps = self.rc.match(url).groups() amazonid = urlgrps[3] #url.split("/")[-2] print "Getting ", amazonid try: p = self.ep.lookup(ItemId=amazonid) except: p = None if p is None: return None return (p.title, p.price_and_currency, p.medium_image_url)
def get_or_create_product(asin): """ Checks the database for an existing ASIN. If not found, try to fetch it using the Amazon Product API. :return: An instance of `products.models.Product` """ try: product = Product.objects.get(asin=asin) except: amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG) az = amazon.lookup(ItemId=asin) product = Product(asin=asin, upc=az.upc, ean=az.ean, description=az.title, image_url=az.large_image_url, amazon_url=az.offer_url) product.save() generate_thumb.delay(product, '600x400') generate_thumb.delay(product, '125x125') product.manufacturer = az.get_attribute('Manufacturer') product.brand = az.get_attribute('Brand') product.model_number = az.get_attribute('Model') product.mpn = az.mpn product.part_number = az.part_number product.sku = az.sku product.isbn = az.isbn product.length = az.get_attribute('ItemDimensions.Length') product.width = az.get_attribute('ItemDimensions.Width') product.height = az.get_attribute('ItemDimensions.Height') product.weight = az.get_attribute('ItemDimensions.Weight') product.save() return product
def parse(self, urlopen_object): product_url = search('http://www.amazon.com/([\\w-]+/)?(dp|gp/product)/(\\w+/)?(\\w{10})', urlopen_object.url) if product_url is not None: id_product = product_url.group(4) amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG) product = amazon.lookup(ItemId=id_product) title = product.title authors = u", ".join(unicode(v) for v in product.authors) price = '{0} {1}'.format(product.price_and_currency[0], product.price_and_currency[1]) description = product.editorial_review if product.medium_image_url is None: book_image_url = '' else: book_image_url = product.medium_image_url return {'title': title, 'authors': authors, 'price': price, 'description': description, 'book_image_url': book_image_url} else: return None
def get_product_information(self): access_key, secret_key, associate_tag = get_config() amz = AmazonAPI(access_key, secret_key, associate_tag) response = amz.lookup(IdType="UPC", ItemId="%s" % self.sku, SearchIndex="Electronics") if type(response) is list: # If more than one response was found, return the first. response = response[0] self.asin = response.asin self.actors = response.actors self.binding = response.binding self.brand = response.brand self.directors = response.directors self.editorial_reviews = response.editorial_reviews self.features = response.features self.genre = response.genre self.large_img = response.large_image_url self.medium_img = response.medium_image_url self.model = response.model self.publication_date = response.publication_date self.release_date = response.release_date self.sales_rank = response.sales_rank self.small_img = response.small_image_url self.title = response.title self.url = response.offer_url self.list_price, self.currency = response.list_price if self.list_price is None: self.list_price = 0.00 if self.currency is None: self.currency = "USD" self.api_filled = True
def update_product(product): url = product.product_url try: AMAZON_ACCESS_KEY = 'AKIAIZPHCO56EZACZHBA' AMAZON_SECRET_KEY = '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' AMAZON_ASSOC_TAG = '1015f-21' region = url.split("amazon.")[1].split("/")[0] if "/dp/" in url: ASIN = url.split("/dp/")[1].strip("/").split("/")[0] elif "/gp/" in url: ASIN = url.split("/gp/product/")[1].strip("/").split("/")[0] print(ASIN) amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region=region.upper()) products = amazon.lookup(ItemId=ASIN) price, currency = products.price_and_currency title = products.title graph = Graph(product_id=product, updated_at=datetime.now(), current_price=price) graph.save() product = Product.objects.get(asin=ASIN) user_products = User_products.objects.filter(product_id=product) for user_product in user_products: if user_product.price_drop_below: print(title, int(price),user_product.email_to) if int(price) <= int(user_product.price_drop_below): print(user_product.user_id_id) print("Price drop value = " + str(user_product.price_drop_below)) print("SENT MAILLLLL TOOOOOO " + str(user_product.email_to)) send_mail('Price dropped!', 'Hi, the price of ' + str(title) + "dropped from " + str(user_product.price_when_added) + " to " + str(price) + "\n\nFollow this link to buy now \n" + str(url), EMAIL_HOST_USER, [user_product.email_to], fail_silently=False) except Exception as e: print("ERROR " + str(e)) return
class AmazonScraper(object): def __init__(self, access_key, secret_key, associate_tag, *args, **kwargs): self.api = AmazonAPI(access_key, secret_key, associate_tag, *args, **kwargs) def reviews(self, ItemId=None, URL=None): return Reviews(self, ItemId, URL) def review(self, Id=None, URL=None): return Review(self, Id, URL) def reviewer(self, url): return Reviewer(url) def lookup(self, URL=None, **kwargs): if URL: kwargs['ItemId'] = extract_asin(URL) result = self.api.lookup(**kwargs) if isinstance(result, (list, tuple)): result = [Product(p) for p in result] else: result = Product(result) return result def similarity_lookup(self, **kwargs): for p in self.api.similarity_lookup(**kwargs): yield Product(p) def browse_node_lookup(self, **kwargs): return self.api.browse_node_lookup(**kwargs) def search(self, **kwargs): for p in self.api.search(**kwargs): yield Product(p) def search_n(self, n, **kwargs): for p in self.api.search_n(n, **kwargs): yield Product(p)
def main(selfStr): config = configparser.ConfigParser() #config.read('config.ini') #AMAZON_KEY = config.get('amazon', 'AMAZON_KEY') AMAZON_KEY = 'YOUR KEY HERE' #AMAZON_SECRET = config.get('amazon', 'AMAZON_SECRET') AMAZON_SECRET = 'YOUR SECRET KEY HERE' #AMAZON_ASSOCIATE = config.get('amazon', 'AMAZON_ASSOCIATE') AMAZON_ASSOCIATE = 'reffit-20' amazon = AmazonAPI(AMAZON_KEY, AMAZON_SECRET, AMAZON_ASSOCIATE) if ('/dp/' in selfStr) or ('/gp/' in selfStr): #try: print 'Finding item...' product = amazon.lookup(ItemId=get_asin(selfStr)) print 'Found item!' title = product.title price = min(product.price_and_currency[0], product.list_price[0]) if (price <= 0): price = max(product.price_and_currency[0], product.list_price[0]) #print product.images[0].LargeImage.URL ''' for im in product.images: print im.LargeImage.URL a = raw_input() ''' image = str(product.images[-1].LargeImage.URL) print title print price print image print 'Starting calculations' link, p, diff = calc_result(title, price, image) print link + ' $:' + str(p) + ' ' + str(diff) return link, p, diff
def amazon_textbook_fields(isbn): if amazon is None: amazon = AmazonAPI( get_secret("AMAZON_ACCESS_KEY"), get_secret("AMAZON_SECRET_KEY"), get_secret("AMAZON_ASSOC_TAG"), ) try: product = amazon.lookup(ItemId=isbn, IdType="ISBN", SearchIndex="Books") except AsinNotFound: return if isinstance(product, list): product = product[0] return { "detail_url": product.detail_page_url, "image_url": product.medium_image_url, "author": product.author, "title": product.title, }
def product(): isbn = request.args.get("isbn", "") data = {} try: AMAZON_ACCESS_KEY = "AKIAJUE7O3QM7ZFIA67A" AMAZON_SECRET_KEY = "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" AMAZON_ASSOC_TAG = "csrgxtu-23" amazon_cn = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="CN") product = amazon_cn.lookup(IdType="ISBN", ItemId=isbn, SearchIndex="Books") data["isbn"] = product.isbn data["author"] = product.author data["price"] = product.price_and_currency[0] data["publisher"] = product.publisher data["available"] = isAvailable(product.to_string()) data["error"] = False # return json.dumps(data) except: data["error"] = True # return json.dumps(data) finally: return json.dumps(data)
def asin_search_api(asin_number): amazon = AmazonAPI(settings.AMAZON_ACCESS_KEY, settings.AMAZON_SECRET_KEY, settings.AMAZON_ASSOC_TAG) product = amazon.lookup(ItemId=asin_number) return product
class Product_API: def __init__(self, aws_access_key, aws_secret_key, associate_tag, region): self.aws_access_key = aws_access_key self.aws_secret_key = aws_secret_key self.associate_tag = associate_tag self.amazon = AmazonAPI(self.aws_access_key, self.aws_secret_key, self.associate_tag, region=region) def restart_program(): python = sys.executable os.execl(python, python, *sys.argv) def formate_string(self, string): return '' if string is None else str(string) def formate_content(self, content): return content.replace('"', ' ').replace('\t', ' ').replace( '\n', ' ').replace('\r', ' ').replace('\u2028', ' ').replace( '\u2029', ' ') if content else '' def timed_out(timeout): def _timed_out(func): @functools.wraps(func) def _func(*args, **kwargs): result = [None] def timed_func(): try: result[0] = func(*args, **kwargs) except Exception as e: result[0] = e alarm = threading.Thread(target=timed_func, daemon=True) try: alarm.start() alarm.join(timeout) except Exception as e: raise e if isinstance(result[0], Exception): raise result[0] return result[0] return _func return _timed_out @timed_out(60) def amazonLookup(self, productid): return self.amazon.lookup(ItemId=productid) def get_product_details(self, productid): data = [] left_asins = {} found_asins = {} try_time = 1 input_asins = dict([item, True] for item in productid.split(',')) # print(input_asins) # print(productid) # products = self.amazon.lookup(ItemId=productid) # try: # products = self.amazon.lookup(ItemId=productid) # except: # print('ASIN(s) ', productid ,' not found') # return data,input_asins try_time = 0 while True: try_time += 1 print("try time: " + str(try_time)) try: products = self.amazonLookup(productid) if products == None: restart_program() break except Exception as err: with open('src/output/log.txt', 'a', encoding='utf-8') as f: f.write( str(err) + '\t' + time.strftime("%Y-%m-%d %H:%M:%S") + '\n') if hasattr(err, 'code') and err.code == 503: print('503 error') time.sleep(1) else: print('ASIN(s) ', productid, ' not found') return data, input_asins # while try_time<10: # try: if type(products) is not list: products = [products] for item in products: asin = item.asin print(asin) found_asins[asin] = True # authors = item.authors # authors = ';'.join(authors) # date = item.publication_date # date = datetime.datetime.strftime(date,'%B %d,%Y') if date else '' #artists = item.artists #artists = ';'.join(artists) isEligibleForPrime = self.formate_string(item.isEligibleForPrime) isPreorder = item.isPreorder if isPreorder: continue #exit() brand = self.formate_content(item.brand) brand = self.formate_string(brand) title = self.formate_content(item.title) manufacturer = self.formate_content(item.manufacturer) manufacturer = self.formate_string(manufacturer) has_review = self.formate_string(item.reviews) upc = self.formate_string(item.upc) color = item.color availability = self.formate_string(item.availability) #part_number = item.part_number editorial_review = '' try: editorial_review = item.editorial_review except: pass # editorial_review = item.editorial_review description = self.formate_content(editorial_review) features = item.features bullet_points = [] for feature in features: if feature: bullet_points.append(self.formate_content(feature)) bullet_point = ';'.join(bullet_points) bullet_points = self.formate_string(bullet_points) #attributes = item.get_attribute('') #browse_nodes = item.browse_nodes new_sellers = self.formate_string(item.TotalNew) if new_sellers == '': new_sellers = '0' image = self.formate_string(item.large_image_url) rank = self.formate_string(item.sales_rank) cankao_price = self.formate_string(item.price_and_currency[0]) #list_price = item.list_price[0] product_group = self.formate_string(item.product_group) binding = self.formate_string(item.binding) color = self.formate_string(item.color) color = self.formate_content(color) length = self.formate_string(item.length) width = self.formate_string(item.width) MaterialType = self.formate_string(item.MaterialType) MetalType = self.formate_string(item.MetalType) #print(item.MetalType) #exit() height = self.formate_string(item.height) weight = item.package_weight if not weight: weight = item.weight weight = self.formate_string(weight) size = self.formate_string(item.size) size = self.formate_content(size) browses_dic = {} browse_nodes = item.browse_nodes browses_name = '' for browse_node in browse_nodes: browses_list = [] child_name = browse_node.name if browses_dic.get(child_name, True): browses_list.append(str(child_name)) browses_dic[child_name] = False ancestors = browse_node.ancestors for ancestor in ancestors: ancestor_name = ancestor.name if browses_dic.get(ancestor_name, True): browses_list.append(str(ancestor_name)) browses_dic[ancestor_name] = False browses_list = browses_list[::-1] browses_name = browses_name + ';' + '>'.join(browses_list) browses_name = self.formate_string(browses_name[1:]) weight_new = weight if not weight_new: weight_new = '0' #if image and brand and prime_price and int(totalNew) and float(weight_new)<=30 : # data.append('\t'.join([asin,title,manufacturer,brand,image,rank,availability,product_group,binding,weight,size,totalNew,isEligibleForPrime,browses_name,bullet_point,description,color,prime_price,upc,length,width,height])) data.append('\t'.join([ asin, title, brand, rank, product_group, availability, new_sellers, has_review, cankao_price ])) # break # except: # #data=[productid] # print('Try time: ',try_time) # try_time +=1 #print(data) for asin in input_asins: if asin not in found_asins: left_asins[asin] = True print(left_asins) return data, left_asins # associate_tag = 'christian' # aws_access_key = 'AKIAI2KC4CSH4A4ZVSGA' # aws_secret_key = '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' # start = datetime.datetime.now() # amazon = AmazonAPI(aws_access_key, aws_secret_key, associate_tag) # product_api = Product_API(aws_access_key,aws_secret_key,associate_tag,'US') # print(product_api.get_product_details('B01BB2H9YK,B014DTV2LE')) # end = start = datetime.datetime.now() # print((end-start).seconds)
def get_product_from_amazon(item_id): amazon = AmazonAPI(keys.AMAZON_CLIENT_KEY, keys.AMAZON_SECRET_KEY, keys.AMAZON_APP_NAME) return amazon.lookup(ItemId=item_id)
image = 'NA' try: asin = re.findall(r'dp\/(.*?)\/', url)[0] except Exception, e: asin = 'NA' try: price_new = re.findall( r'\d+.\d+', elem.find(attrs={ 'class': 'a-size-base a-color-price s-price a-text-bold' }).getText())[0] except Exception, e: try: product = amazon_uk.lookup(ItemId=unidecode(asin)) price_new = str(product.price_and_currency[0]) if price_new is not None: price_new = price_new else: price_new = 'NA' except: try: product = amazon_uk1.lookup(ItemId=unidecode(asin)) price_new = str(product.price_and_currency[0]) if price_new is not None: price_new = price_new else: price_new = 'NA' except: try:
class TestAmazonApi(TestCase): """Test Amazon API Test Class for Amazon simple API wrapper. """ def setUp(self): """Set Up. Initialize the Amazon API wrapper. The following values: * AMAZON_ACCESS_KEY * AMAZON_SECRET_KEY * AMAZON_ASSOC_TAG Are imported from a custom file named: 'test_settings.py' """ self.amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) def test_lookup(self): """Test Product Lookup. Tests that a product lookup for a kindle returns results and that the main methods are working. """ product = self.amazon.lookup(ItemId="B007HCCNJU") assert_true('Kindle' in product.title) assert_equals(product.ean, '0814916017775') assert_equals(product.large_image_url, 'http://ecx.images-amazon.com/images/I/41VZlVs8agL.jpg') assert_equals(product.get_attribute('Publisher'), 'Amazon') assert_equals( product.get_attributes( ['ItemDimensions.Width', 'ItemDimensions.Height']), { 'ItemDimensions.Width': '650', 'ItemDimensions.Height': '130' }) assert_true(len(product.browse_nodes) > 0) assert_true(product.price_and_currency[0] is not None) assert_true(product.price_and_currency[1] is not None) assert_equals(product.browse_nodes[0].id, 2642129011) assert_equals(product.browse_nodes[0].name, 'eBook Readers') def test_batch_lookup(self): """Test Batch Product Lookup. Tests that a batch product lookup request returns multiple results. """ asins = [ 'B0051QVESA', 'B005DOK8NW', 'B005890G8Y', 'B0051VVOB2', 'B005890G8O' ] products = self.amazon.lookup(ItemId=','.join(asins)) assert_equals(len(products), 5) for i, product in enumerate(products): assert_equals(asins[i], product.asin) def test_search(self): """Test Product Search. Tests that a product search is working (by testing that results are returned). And that each result has a title attribute. The test fails if no results where returned. """ products = self.amazon.search(Keywords='kindle', SearchIndex='All') for product in products: assert_true(hasattr(product, 'title')) break else: assert_true(False, 'No search results returned.') def test_search_n(self): """Test Product Search N. Tests that a product search n is working by testing that N results are returned. """ products = self.amazon.search_n(1, Keywords='kindle', SearchIndex='All') assert_equals(len(products), 1) def test_amazon_api_defaults_to_US(self): """Test Amazon API defaults to the US store.""" amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) assert_equals(amazon.api.Region, "US") def test_search_amazon_uk(self): """Test Poduct Search on Amazon UK. Tests that a product search on Amazon UK is working and that the currency of any of the returned products is GBP. The test fails if no results were returned. """ amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="UK") assert_equals(amazon.api.Region, "UK", "Region has not been set to UK") products = amazon.search(Keywords='Kindle', SearchIndex='All') currencies = [product.price_and_currency[1] for product in products] assert_true(len(currencies), "No products found") is_gbp = 'GBP' in currencies assert_true(is_gbp, "Currency is not GBP, cannot be Amazon UK, though") def test_similarity_lookup(self): """Test Similarity Lookup. Tests that a similarity lookup for a kindle returns 10 results. """ products = self.amazon.similarity_lookup(ItemId="B0051QVF7A") assert_equals(len(products), 10) def test_product_attributes(self): """Test Product Attributes. Tests that all product that are supposed to be accessible are. """ product = self.amazon.lookup(ItemId="B0051QVF7A") for attribute in PRODUCT_ATTRIBUTES: getattr(product, attribute) def test_browse_node_lookup(self): """Test Browse Node Lookup. Test that a lookup by Brose Node ID returns appropriate node. """ bnid = 2642129011 bn = self.amazon.browse_node_lookup(BrowseNodeId=bnid)[0] assert_equals(bn.id, bnid) assert_equals(bn.name, 'eBook Readers') assert_equals(bn.is_category_root, False)
from amazon.api import AmazonAPI amazon = AmazonAPI("AKIAI6DA7AZ35GPPONJQ", "lngMtLZjOI+k3zrmGqXeck5cyuNJXoMnbyIhyI8Q", "hat07c-20") product = amazon.lookup(ItemId='B00EOE0WKQ') product.title
attrs={'class': 'reviewCountTextLinkedHistogram noUnderline'})['title'] page1 = mech.open('http://www.amazon.com/product-reviews/' + asin) html1 = page1.read() soup1 = BeautifulSoup(str(html1)) data1 = BeautifulSoup.extract((soup1)) Ratings = data1.findAll(attrs={'class': 'a-histogram-row'}) Stars_and_numbers = {} for rating in Ratings: key = rating.findAll( attrs={'class': 'a-text-right aok-nowrap'})[0].text value = s.findAll(attrs={'class': 'a-text-right aok-nowrap'})[1].text Stars_and_numbers[key] = value #Stars_and_numbers = data.find(attrs = {'class':'a-icon-alt'}).getText() Product_Link = url product_0 = amazon.lookup(ItemId=asin) Description = product_0.editorial_review features = data.find(attrs={'id': 'feature-bullets'}).findAll('li') Feature1 = features[1].getText() Feature2 = features[2].getText() Feature3 = features[3].getText() Feature4 = features[4].getText() Feature5 = features[5].getText() breadcrums = data.find(attrs={ 'class': 'a-subheader a-breadcrumb feature' }).findAll('li') b = '' i = 0 for bread in breadcrums: if i % 2 == 0:
('192.168.2.255', 6001)) counter += 1 except: # no keyword found continue # Try finding a product using our keyword, and jump to the next loop of there was none try: products = amazon.search_n(1, Keywords=keyword, SearchIndex='All') print products[0].asin except Exception, e: print e continue # Lookup info of our product, and jump to the next loop of there was none try: product = amazon.lookup(ItemId=products[0].asin) if product.large_image_url == None: continue except Exception, e: print "error lookup" print e continue # Tell our receiver about the found image print "sending: dash,{counter},found,{img_url}".format( counter=counter, img_url=product.large_image_url) s.sendto( "dash,{counter},found,{img_url}".format( counter=counter, img_url=product.large_image_url), 0, ('192.168.2.255', 6001)) s.sendto(