From 28115c270644b5daca51c59c974b8e00f903e432 Mon Sep 17 00:00:00 2001 From: Alex Kaszynski Date: Fri, 27 Oct 2023 15:13:36 -0700 Subject: [PATCH] Add number of products to product finder (#151) * add number of products to product finder * do not add key each time * use dictionary merge instead --- src/keepa/interface.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/keepa/interface.py b/src/keepa/interface.py index 78f8c38..fddee35 100644 --- a/src/keepa/interface.py +++ b/src/keepa/interface.py @@ -1333,7 +1333,7 @@ def seller_query( response = self._request("seller", payload, wait=wait) return _parse_seller(response["sellers"], to_datetime) - def product_finder(self, product_parms, domain="US", wait=True) -> list: + def product_finder(self, product_parms, domain="US", wait=True, n_products=50) -> list: """Query the keepa product database to find products matching criteria. Almost all product fields can be searched for and sort. @@ -2356,6 +2356,9 @@ def product_finder(self, product_parms, domain="US", wait=True) -> list: wait : bool, default: True Wait available token before doing effective query. + n_products : int, default 50 + Maximum number of matching products returned by keepa. + Returns ------- list @@ -2369,8 +2372,8 @@ def product_finder(self, product_parms, domain="US", wait=True) -> list: Examples -------- - Query for all of Jim Butcher's books using the synchronous - ``keepa.Keepa`` class. Sort by current sales + Query for the first 100 of Jim Butcher's books using the synchronous + ``keepa.Keepa`` class. Sort by current sales. >>> import keepa >>> api = keepa.Keepa('') @@ -2378,8 +2381,7 @@ def product_finder(self, product_parms, domain="US", wait=True) -> list: ... 'author': 'jim butcher', ... 'sort': ["current_SALES", "asc"], ... } - - >>> asins = api.product_finder(product_parms) + >>> asins = api.product_finder(product_parms, n_products=100) >>> asins ['B000HRMAR2', '0578799790', @@ -2423,7 +2425,7 @@ def product_finder(self, product_parms, domain="US", wait=True) -> list: payload = { "key": self.accesskey, "domain": DCODES.index(domain), - "selection": json.dumps(product_parms), + "selection": json.dumps({**product_parms, **{'perPage': n_products}}), } response = self._request("query", payload, wait=wait)