From 40612b9995fbc0d7428e021d26bf162f52ffcaf8 Mon Sep 17 00:00:00 2001 From: Aaron Godfrey Date: Thu, 29 Oct 2020 16:22:37 -0700 Subject: [PATCH] Change search index for North American countries for better results. --- custom_components/nintendo_wishlist/eshop.py | 14 +++++++------- tests/test_eshop.py | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/custom_components/nintendo_wishlist/eshop.py b/custom_components/nintendo_wishlist/eshop.py index 308b50e..6818bee 100644 --- a/custom_components/nintendo_wishlist/eshop.py +++ b/custom_components/nintendo_wishlist/eshop.py @@ -14,8 +14,8 @@ # North American countries. NA_COUNTRIES: Tuple[str] = ("CA", "US") NA_INDEX_NAMES: Dict[str, str] = { - "CA": "noa_aem_game_en_ca", - "US": "noa_aem_game_en_us", + "CA": "ncom_game_en_ca", + "US": "ncom_game_en_us", } # Mapping of country code to language code. NOTE: language must be lowercase @@ -64,11 +64,11 @@ class Country(enum.Enum): # Below constants used by North America (US and CA) APP_ID = "U3B6GR4UA3" -API_KEY = "9a20c93440cf63cf1a7008d75f7438bf" +API_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7" QUERIES = [ { - "indexName": "noa_aem_game_en_us", - "params": "query=&hitsPerPage=350&maxValuesPerFacet=30&facets=%5B%22generalFilters%22%2C%22platform%22%2C%22availability%22%2C%22categories%22%2C%22filterShops%22%2C%22virtualConsole%22%2C%22characters%22%2C%22priceRange%22%2C%22esrb%22%2C%22filterPlayers%22%5D&tagFilters=&facetFilters=%5B%5B%22generalFilters%3ADeals%22%5D%2C%5B%22platform%3ANintendo%20Switch%22%5D%5D", # noqa + "indexName": "ncom_game_en_us", + "params": "query=&hitsPerPage=350&maxValuesPerFacet=30&page=0&analytics=false&facets=%5B%22generalFilters%22%2C%22platform%22%2C%22availability%22%2C%22genres%22%2C%22howToShop%22%2C%22virtualConsole%22%2C%22franchises%22%2C%22priceRange%22%2C%22esrbRating%22%2C%22playerFilters%22%5D&tagFilters=&facetFilters=%5B%5B%22platform%3ANintendo%20Switch%22%5D%2C%5B%22generalFilters%3ADeals%22%5D%5D", # noqa }, ] @@ -105,7 +105,7 @@ async def fetch_on_sale(self) -> Dict[int, SwitchGame]: def get_na_switch_game(self, game: Dict[str, Any]) -> SwitchGame: """Get a SwitchGame from a json result.""" - box_art = game.get("boxArt", game.get("gallery")) + box_art = game.get("boxart", game.get("gallery")) if not box_art or not box_art.endswith((".png", ".jpg")): raise ValueError("Couldn't find box art: %s", game) @@ -133,7 +133,7 @@ async def _get_page( queries[0]["params"] = query_params data = await client.multiple_queries_async(queries) # Filter out resuls w/o box art. - games = [r for r in data["results"][0]["hits"] if r.get("boxArt")] + games = [r for r in data["results"][0]["hits"] if r.get("boxart")] result["games"] = self.filter_wishlist_matches(games) result["num_pages"] = data["results"][0]["nbPages"] return result diff --git a/tests/test_eshop.py b/tests/test_eshop.py index ef97d15..43a0125 100644 --- a/tests/test_eshop.py +++ b/tests/test_eshop.py @@ -11,14 +11,14 @@ def client_mock(): client = Mock() games = [ { - "boxArt": "image.png", + "boxart": "image.png", "msrp": 24.99, "nsuid": 70010000531, "salePrice": 9.99, "title": "Picross", }, { - "boxArt": "image.png", + "boxart": "image.png", "msrp": 14.99, "nsuid": 70010000532, "salePrice": 8.24, @@ -62,7 +62,7 @@ def test_get_na_switch_game_bad_prefix_value_error(): wishlist = ["title1"] eshop = EShop("US", Mock(), wishlist) with pytest.raises(ValueError, match="Couldn't find box art"): - game = {"boxArt": "https://nintendo.com/art.gif"} + game = {"boxart": "https://nintendo.com/art.gif"} eshop.get_na_switch_game(game) @@ -71,7 +71,7 @@ def test_get_na_switch_game_success(): wishlist = ["title1"] eshop = EShop("US", Mock(), wishlist) game = { - "boxArt": "image.png", + "boxart": "image.png", "msrp": 14.99, "nsuid": 70010000532, "salePrice": 8.24,