Skip to content

Commit 5e5dd1d

Browse files
committed
Removed Amazon 10 products limitation
1 parent 830cf5d commit 5e5dd1d

3 files changed

Lines changed: 49 additions & 40 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Features
1414

1515
* Object oriented interface for simple usage.
1616
* Get information about a product through its ASIN or URL.
17-
* Get multiple products at once.
17+
* Get multiple products at once without the 10 products limitation from Amazon.
1818
* Configurable throttling to avoid requests exceptions.
1919
* Support for all available countries.
2020
* Reorganized product information [structure](https://github.com/sergioteula/python-amazon-paapi/blob/master/PRODUCT.md) for simple use.
@@ -53,9 +53,12 @@ Get the ASIN from a URL:
5353

5454
Changelog
5555
-------------
56-
Version 2.0.2
57-
- Added some type hints.
56+
Version 2.1.0
57+
- Changed get_product method name to get_products.
58+
- Removed Amazon 10 products limitation.
59+
- Added type hints.
5860
- Solved bug with images exception.
61+
- Updated documentation.
5962

6063
Version 2.0.1
6164
- Improved exception handling.

amazon/paapi.py

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class Class:
4747
"""Base class for creating the product instance."""
4848

4949

50+
def _chunks(lst, n):
51+
"""Yield successive n-sized chunks from lst."""
52+
for i in range(0, len(lst), n):
53+
yield lst[i:i + n]
54+
55+
5056
def get_asin(url: str):
5157
"""Find the ASIN from a given URL.
5258
@@ -567,7 +573,10 @@ class instance: An instance of the class Product containing all the available
567573
asin_or_url_list = [x.strip() for x in product_ids.split(",")] if isinstance(product_ids, str) else product_ids
568574

569575
# Extract ASIN if supplied input is product URL and remove any duplicate ASIN
570-
asin_list = list(set([get_asin(x) for x in asin_or_url_list[:10]]))
576+
asin_full_list = list(set([get_asin(x) for x in asin_or_url_list]))
577+
578+
# Creates lists of 10 items each
579+
asin_full_list = list(_chunks(asin_full_list, 10))
571580

572581
product_resources = [
573582
GetItemsResource.BROWSENODEINFO_BROWSENODES,
@@ -626,38 +635,35 @@ class instance: An instance of the class Product containing all the available
626635
GetItemsResource.RENTALOFFERS_LISTINGS_DELIVERYINFO_SHIPPINGCHARGES,
627636
GetItemsResource.RENTALOFFERS_LISTINGS_MERCHANTINFO]
628637

629-
try:
630-
request = GetItemsRequest(partner_tag=self.tag,
631-
partner_type=PartnerType.ASSOCIATES,
632-
marketplace=self.marketplace,
633-
condition=condition,
634-
item_ids=asin_list,
635-
resources=product_resources)
636-
except Exception as exception:
637-
raise exception
638-
639-
try:
640-
# Wait before doing the request
641-
wait_time = 1 / self.throttling - (time.time() - self.last_query_time)
642-
if wait_time > 0:
643-
time.sleep(wait_time)
644-
self.last_query_time = time.time()
645-
646-
response = api.get_items(request)
647-
if response.items_result is not None:
648-
if len(response.items_result.items) > 0:
649-
results = []
650-
for item in response.items_result.items:
651-
product = parse_product(item)
652-
results.append(product)
653-
if len(results) == 0:
654-
return None
655-
elif len(results) == 1:
656-
return results[0]
657-
else:
658-
return results
659-
else:
660-
return None
661-
662-
except Exception as exception:
663-
raise exception
638+
results = []
639+
for asin_list in asin_full_list:
640+
try:
641+
request = GetItemsRequest(partner_tag=self.tag,
642+
partner_type=PartnerType.ASSOCIATES,
643+
marketplace=self.marketplace,
644+
condition=condition,
645+
item_ids=asin_list,
646+
resources=product_resources)
647+
except Exception as exception:
648+
raise exception
649+
650+
try:
651+
# Wait before doing the request
652+
wait_time = 1 / self.throttling - (time.time() - self.last_query_time)
653+
if wait_time > 0:
654+
time.sleep(wait_time)
655+
self.last_query_time = time.time()
656+
657+
response = api.get_items(request)
658+
if response.items_result is not None:
659+
if len(response.items_result.items) > 0:
660+
for item in response.items_result.items:
661+
product = parse_product(item)
662+
results.append(product)
663+
except Exception as exception:
664+
raise exception
665+
666+
if results:
667+
return results
668+
else:
669+
return None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='python-amazon-paapi',
8-
version='2.0.2',
8+
version='2.1.0',
99
author='Sergio Abad',
1010
author_email='sergio.abad@bytelix.com',
1111
description='Amazon Product Advertising API 5.0 wrapper for Python',

0 commit comments

Comments
 (0)