from typing import Any, Dict, Set from apollo_notifications.constants import GLOBAL_MARKET from apollo_notifications.user_data.client import UserDataClient from constants import SYNONYM_MARKETS class ApplePlaylistsAdditionsUDClient(UserDataClient): def _parse_settings_item( self, item: Dict[str, Any], vendor: str, user_id_map: Dict[str, int], market_to_users_map: Dict[str, Set[str]] ): """Parse user settings item and add data to the passed structures. Args: item: settings item to parse. vendor: dsp to filter settings for. user_id_map: map of user_id to account_id. market_to_users_map: map of market to set of user interesting in getting notification for this market and passed vendor. """ item_settings = item.get("data", {}) user_id, account_id, markets = item.get("user_id"), item.get("account_id"), item_settings.get("markets", []) if not user_id or not markets: self._logger.warning(f"Settings parser got item without 'user_id' or/and 'markets', skipped: {item}.") return if not item_settings.get("notifications") or not item_settings.get("vendors", {}).get(vendor): return user_id_map[user_id] = account_id if not markets: return markets_set = set(markets) # according to AG-3362 for apple playlist additions we should send notifications related to US only # if user has US and Global both added. if (markets_set & SYNONYM_MARKETS) == SYNONYM_MARKETS: markets_set.remove(GLOBAL_MARKET) for market in markets_set: market_to_users_map.setdefault(market.lower(), set()).add(user_id)