@@ -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+
5056def 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
0 commit comments