当前位置: 首页>>代码示例>>Python>>正文


Python AmazonAPI.search_n方法代码示例

本文整理汇总了Python中amazon.api.AmazonAPI.search_n方法的典型用法代码示例。如果您正苦于以下问题:Python AmazonAPI.search_n方法的具体用法?Python AmazonAPI.search_n怎么用?Python AmazonAPI.search_n使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在amazon.api.AmazonAPI的用法示例。


在下文中一共展示了AmazonAPI.search_n方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search_item

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
def search_item():
    query = request.args.get('q')
    category = request.args.get('c')
    ## replace confidencial to secret file and put it in gitignore
    from amazon.api import AmazonAPI
    amazon = AmazonAPI(os.environ['AWS_ACCESS_KEY'], os.environ['AWS_SECRET_KEY'], 'papylus-22', region="JP")

    if not category:
        category = 'All'

    try:
        products = amazon.search_n(5, Keywords=query, SearchIndex=category)
    except:
        # in case 503 Error occurs without any reason
        import time
        for i in range(3):
            print '503 Error'
            time.sleep(1)
            products = amazon.search_n(5, Keywords=query, SearchIndex=category)
            if products:
                break

    items = []
    for i in products:
        pub_date = i.publication_date.strftime(u'%Y-%m-%d') if i.publication_date != None else ''
        items.append({'name': i.title, 'url': i.offer_url, 'img': i.medium_image_url, 'publisher': i.publisher, 'pub_date': pub_date})
    return json.dumps(items)
开发者ID:kmagai,项目名称:papylus,代码行数:29,代码来源:controllers.py

示例2: Item

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
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
开发者ID:fmoezinia,项目名称:flask_files,代码行数:37,代码来源:product_search.py

示例3: AmazonScraper

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
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)
开发者ID:kinglouisxviii,项目名称:amazon_scraper,代码行数:37,代码来源:__init__.py

示例4: get

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
    def get(self):
        search = self.request.get('search')
        amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG) #initiates a new Amazon API
        amazon_results = amazon.search_n(15, Keywords=search, SearchIndex='All')

        # returns in JSON name, salePrice, and URL of user's search from BestBuy
        best_buy_url = 'http://api.remix.bestbuy.com/v1/products(search='+ search.replace(' ', '&search=')+')?format=json&show=sku,name,salePrice,url,image,upc&pageSize=15&page=5&apiKey=24ta6vtsr78a22fmv8ngfjet'
        best_buy_results = json.load(urllib2.urlopen(best_buy_url)).get('products')

        walmart_url = "http://api.walmartlabs.com/v1/search?query=%s&format=json&apiKey=cz9kfm3vuhssnk6hn33zg86k&responseGroup=base" % search.replace(' ','+')
        walmart_results = json.load(urllib2.urlopen(walmart_url)).get('items')

        results = []
        for product in amazon_results:
            results += [(product.title, product.price_and_currency[0], product.offer_url, product.medium_image_url, 'Amazon','/wishlist?type=amazon&id=%s'%product.asin,"/compare?upc=%s" %str(product.upc), '/email?producturl=%s'%product.offer_url)]
            #How to retrive asin for amazon products and decrease image size
        for product in best_buy_results:
            results += [(product.get('name'), product.get('salePrice'), product.get('url'), product.get('image'), 'Best Buy','/wishlist?type=bestbuy&id=%s'%product.get('sku'),"/compare?upc=%s" %str(product.get('upc')), '/email?producturl=%s'%product.get('url'))]
        for product in walmart_results:
            results += [(product.get('name'), product.get('salePrice'), product.get('productUrl'), product.get('thumbnailImage'), 'Walmart','/wishlist?type=walmart&id=%s'%product.get('itemId'),"/compare?upc=%s" %str(product.get('upc')),'/email?producturl=%s'%product.get('productUrl'))]

        results = sorted(results,key=lambda x: x[1])

        for item in results:
            i = results.index(item)
            if str(item[1])[len(str(item[1]))-2] == '.':
                item = list(item)
                item[1] = str(item[1]) + '0'
                item = tuple(item)
                results[i] = item
        template_variables={"user_search":search, 'results':results, 'user': users.get_current_user(),  'logout' : users.create_logout_url('/'), 'login' : users.create_login_url('/')}
        template=jinja_environment.get_template('/templates/results.html')
        self.response.write(template.render(template_variables))
开发者ID:gegbo,项目名称:lowest_current_deals,代码行数:35,代码来源:main.py

示例5: asin_search

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
 def asin_search(self):
     try:
         amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, settings.AWS_ASSOCIATE_TAG)
         products = amazon.search_n(10, Keywords="%s %s" % (self.company.name, self.number), SearchIndex="All")
     except:
         products = None
     return products
开发者ID:phrac,项目名称:partflux,代码行数:9,代码来源:models.py

示例6: __init__

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
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
开发者ID:AlecSKlein,项目名称:GiftlyAPI,代码行数:62,代码来源:giftly_amazon.py

示例7: __init__

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
class AmazonService:

    __API_VERSION = '2013-08-01'

    def __init__(self, title, country):
        self.title = title
        self.country = country

        env_vars = self.get_amazon_env_variables()
        self.amazon = AmazonAPI(env_vars['access_key'],
                                env_vars['secret_key'],
                                env_vars['associates_tag'],
                                Region=self.country,
                                Version=self.__API_VERSION)

    def get_price(self):
        products = self.amazon.search_n(10,
                                        Keywords=self.title + ' [Blu-ray]',
                                        SearchIndex='All')

        ranked_products = self.rank_products(products)
        product = ranked_products[0]

        price = Price()
        price.price = list(product.price_and_currency)
        price.list_price = list(product.list_price)
        price.link = product.offer_url

        return price

    def rank_products(self, products):
        ranked_products = sorted(products, key=lambda x: self.product_score(x), reverse=True)

        return ranked_products

    def product_score(self, p):
        title = str(p.title)
        title = title.replace('[Blu-ray]', '')
        title = title.replace('(Bilingual)', '')
        title = title.replace('(Region Free)', '')
        title = title.strip(' ')
        size_diff = abs(len(title) - len(self.title))

        p_score = 1 if size_diff == 0 else 0
        p_score += 1 if re.search('[Blu\-ray]', p.title) else p_score

        return p_score

    def get_amazon_env_variables(self):
        access_key = os.environ.get('AWS_ACCESS_KEY_ID')
        secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
        associates_tag = os.environ.get('AWS_ASSOCIATES_TAG')

        env_variables = {'access_key': access_key,
                         'secret_key': secret_key,
                         'associates_tag': associates_tag}

        return env_variables
开发者ID:jeremyrea,项目名称:caterblu,代码行数:60,代码来源:amazon_service.py

示例8: generate_csv

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
def generate_csv():
  # initialize amazon api with access key, secret key, and associate tag
  amazon = AmazonAPI('AKIAJPT5M67Z5DB6R3XA', 'P0ekhRiDVDC2xeJa4fZz1P5qHY/B2Qig71G6wZB3', 'thedeepdark-20')

  print("Querying amazon API")
  # returns available book subjects
  subjects = amazon.browse_node_lookup(BrowseNodeId=1000)

  f = open('data.csv', 'wb')
  writer = csv.writer(f)

  print("\tReturned with " + str(len(subjects[0].children)) + " subjects")

  # creates books and author lists
  for subject in subjects:
    for genre in subject.children:
      # skip calendar entries
      if genre.name.text == 'Calendars': continue

      # returns first 1000 entries in each subject
      # Amazons api limits the number of return pages to 10
      # with 10 items on each for a maximum of 100 items 
      books = amazon.search_n(100, Condition='All', BrowseNode=genre.id, SearchIndex='Books', MaxQPS=0.9)

      print("Queried " + genre.name + ", returned " + str(len(books)) + " books")

      failed = 0

      for book in books:
        b_isbn = book.isbn
        b_title = book.title
        b_pub_date = str(book.publication_date)
        b_genre = genre.name
        b_publisher = book.publisher
        b_list_price = book.list_price[0]
        b_price = book.price_and_currency[0]

        if len(book.authors) == 0:
          break

        book_item = [b_isbn, b_title, book.authors[0], b_pub_date, b_publisher, b_genre, b_list_price, b_price]

        for x in range(len(book_item)):
         if isinstance(book_item[x], str):
           book_item[x] = unicode(book_item[x], 'utf-8')
  
        try:
          writer.writerow(book_item)
        except UnicodeEncodeError:
          failed += 1

      print("\tDone processing books, failed to convert unicode characters " + str(failed) + " times")

      time.sleep(5)
开发者ID:jasonb5,项目名称:cins370,代码行数:56,代码来源:scrape.py

示例9: func

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
def func(product):
	#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)

	products = amazon.search_n(1,Keywords= product, SearchIndex= "All")

	print products
开发者ID:fmoezinia,项目名称:mymagic_amazon,代码行数:14,代码来源:product_test_func.py

示例10: keywordSearch

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
def keywordSearch(keywords):
	'''Searches for top 50 results on Amazon of keywords entered by user'''
	amazon = AmazonAPI(amazonAccessKey, amazonSecretKey, amazonAssocTag)
	products = amazon.search_n(50, Keywords=keywords, SearchIndex='All')
	title = ['i', 'i']
	image = ['']
	listPrice = ['']
	for counter, product in enumerate(products):
		title.insert(counter, product.title)
		image.insert(counter, product.large_image_url)
		listPrice.insert(counter, product.price_and_currency)
	return title, image, listPrice
开发者ID:seanziegler,项目名称:amazonvenv,代码行数:14,代码来源:amazonapi.py

示例11: prod_search

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
	def prod_search(self):

		#insert amazon web services credentials
		#associate TAG must be updated every 180 days, make new amazon associates account to get new tag

		amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)

		products_found = amazon.search_n(1,Keywords= self.product, SearchIndex= "All")

		try: 
			return products_found[0].title
		except IndexError:
			return 'No such item available'
开发者ID:fmoezinia,项目名称:mymagic_amazon,代码行数:15,代码来源:product_search.py

示例12: get_amazon_order

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
def get_amazon_order(item):
    amazon = AmazonAPI(AWS['AMAZON_KEY'], AWS['SECRET_KEY'], AWS['ASSOCIATE_TAG'])
    if len(item) > 0:
        try:
            product = amazon.search_n(1, Keywords=item, SearchIndex='All')
            try:
                return product[0]
            except IndexError:
                return None
        except AmazonException:
            return None
    else:
        return None
开发者ID:kevincianfarini,项目名称:reddit-bot,代码行数:15,代码来源:bot.py

示例13: fetch_from_amazon

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
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
开发者ID:thebmo,项目名称:NESRandomizer,代码行数:17,代码来源:nes_extras.py

示例14: prod_asin

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
	def prod_asin(self):

		#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)

		products_found = amazon.search_n(1,Keywords= self.product, SearchIndex= "All")

		
		try: 
			return products_found[0].asin
		except IndexError:
			return 'No product available'	
开发者ID:fmoezinia,项目名称:mymagic_amazon,代码行数:19,代码来源:product_search.py

示例15: search

# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import search_n [as 别名]
def search(request):
    if request.method == 'POST':
        searchvalue = request.POST.get('searchbox', '')
        saved_or_not = request.POST.get('saved_or_not', '')
        amazon = AmazonAPI(ACCESS_KEY, SECRET_KEY, ASSOC_ID)
        products = amazon.search_n(20, Keywords=searchvalue, SearchIndex='All')
        context = {
            'search': searchvalue,
            'products': products
        }
        if saved_or_not == 'saved':
            for product in products:
                if product.title and product.offer_url and product.large_image_url and product.formatted_price and product.price_and_currency:
                    gift = Gift(name=product.title, link=product.offer_url, image_link=product.large_image_url, price_desc=product.formatted_price, price=product.price_and_currency[0])
                    gift.save()

    else:
        context = {}
    return render(request, 'azsearch/search.html', context)
开发者ID:svsaraf,项目名称:giftpier,代码行数:21,代码来源:views.py


注:本文中的amazon.api.AmazonAPI.search_n方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。