Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add number of products to product finder #151

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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