Skip to content

Commit

Permalink
Add number of products to product finder (#151)
Browse files Browse the repository at this point in the history
* add number of products to product finder

* do not add key each time

* use dictionary merge instead
  • Loading branch information
akaszynski authored Oct 27, 2023
1 parent 0af5971 commit 28115c2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/keepa/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -2369,17 +2372,16 @@ 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('<ENTER_ACTUAL_KEY_HERE>')
>>> product_parms = {
... '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',
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 28115c2

Please sign in to comment.