Skip to content

Commit

Permalink
Change search index for North American countries for better results.
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed Oct 29, 2020
1 parent 4477dec commit 40612b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions custom_components/nintendo_wishlist/eshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
},
]

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test_eshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)


Expand All @@ -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,
Expand Down

0 comments on commit 40612b9

Please sign in to comment.