diff --git a/src/keepa/interface.py b/src/keepa/interface.py index 2b14448..65cd22c 100644 --- a/src/keepa/interface.py +++ b/src/keepa/interface.py @@ -44,8 +44,8 @@ def wrapper(target): # domain codes # Valid values: [ 1: com | 2: co.uk | 3: de | 4: fr | 5: -# co.jp | 6: ca | 7: cn | 8: it | 9: es | 10: in | 11: com.mx ] -DCODES = ["RESERVED", "US", "GB", "DE", "FR", "JP", "CA", "CN", "IT", "ES", "IN", "MX"] +# co.jp | 6: ca | 7: cn | 8: it | 9: es | 10: in | 11: com.mx | 12: com.br ] +DCODES = ["RESERVED", "US", "GB", "DE", "FR", "JP", "CA", "CN", "IT", "ES", "IN", "MX", "BR"] # csv indices. used when parsing csv and stats fields. # https://github.com/keepacom/api_backend @@ -506,9 +506,9 @@ def query( timestamps (unix epoch time milliseconds) or two date strings (ISO8601, with or without time in UTC). - domain : str, optional + domain : str, default: "US" One of the following Amazon domains: RESERVED, US, GB, DE, - FR, JP, CA, CN, IT, ES, IN, MX Defaults to US. + FR, JP, CA, CN, IT, ES, IN, MX, BR. offers : int, optional Adds available offers to product data. Default 0. Must be between @@ -886,7 +886,7 @@ def _product_query(self, items, product_code_is_asin=True, **kwargs): domain : str One of the following Amazon domains: - RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX + RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR. offers : bool, optional Adds product offers to product data. @@ -1022,10 +1022,9 @@ def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True) the best sellers list for. You can find category node ids via the category search "search_for_categories". - domain : str - Amazon locale you want to access. Must be one of the following - RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX - Default US. + domain : str, default: "US" + Amazon locale you want to access. Must be one of the following: + RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR. wait : bool, optional Wait available token before doing effective query. @@ -1078,7 +1077,10 @@ def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True) ... """ - assert domain in DCODES, "Invalid domain code" + if domain not in DCODES: + raise ValueError( + f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}" + ) payload = { "key": self.accesskey, @@ -1101,10 +1103,9 @@ def search_for_categories(self, searchterm, domain="US", wait=True) -> list: searchterm : str Input search term. - domain : str, default: 'US' - Amazon locale you want to access. Must be one of the following - RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX - Default US. + domain : str, default: "US" + Amazon locale you want to access. Must be one of the following: + RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR. wait : bool, default: True Wait available token before doing effective query. @@ -1137,7 +1138,10 @@ def search_for_categories(self, searchterm, domain="US", wait=True) -> list: 144 Science Fiction & Fantasy """ - assert domain in DCODES, "Invalid domain code" + if domain not in DCODES: + raise ValueError( + f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}" + ) payload = { "key": self.accesskey, @@ -1163,9 +1167,8 @@ def category_lookup(self, category_id, domain="US", include_parents=False, wait= categories. domain : str, default: "US" - Amazon locale you want to access. Must be one of the following - RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX - Default US + Amazon locale you want to access. Must be one of the following: + RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR. include_parents : bool, default: False Include parents. @@ -1212,7 +1215,9 @@ def category_lookup(self, category_id, domain="US", include_parents=False, wait= """ if domain not in DCODES: - raise ValueError("Invalid domain code") + raise ValueError( + f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}" + ) payload = { "key": self.accesskey, @@ -2885,7 +2890,10 @@ async def _product_query(self, items, product_code_is_asin=True, **kwargs): @is_documented_by(Keepa.best_sellers_query) async def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True): """Documented by Keepa.best_sellers_query.""" - assert domain in DCODES, "Invalid domain code" + if domain not in DCODES: + raise ValueError( + f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}" + ) payload = { "key": self.accesskey, @@ -2903,7 +2911,10 @@ async def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait @is_documented_by(Keepa.search_for_categories) async def search_for_categories(self, searchterm, domain="US", wait=True): """Documented by Keepa.search_for_categories.""" - assert domain in DCODES, "Invalid domain code" + if domain not in DCODES: + raise ValueError( + f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}" + ) payload = { "key": self.accesskey, @@ -2923,7 +2934,10 @@ async def search_for_categories(self, searchterm, domain="US", wait=True): @is_documented_by(Keepa.category_lookup) async def category_lookup(self, category_id, domain="US", include_parents=0, wait=True): """Documented by Keepa.category_lookup.""" - assert domain in DCODES, "Invalid domain code" + if domain not in DCODES: + raise ValueError( + f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}" + ) payload = { "key": self.accesskey, diff --git a/tests/test_interface.py b/tests/test_interface.py index e93e1f3..0e96ddd 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -311,9 +311,10 @@ def test_productquery_offers_multiple(api): def test_domain(api): - request = api.query(PRODUCT_ASIN, history=False, domain="DE") + asin = "0394800028" + request = api.query(asin, history=False, domain="BR") product = request[0] - assert product["asin"] == PRODUCT_ASIN + assert product["asin"] == asin def test_invalid_domain(api):