def _fetch_games(self, key_type: str, lookup_keys: List[str]) -> List[Optional[TwitchGame]]: all_entries: List[Optional[TwitchGame]] = [] # We can fetch a maximum of 100 users on each helix request # so we do it in chunks of 100 for lookup_keys_chunk in iterate_in_chunks(lookup_keys, 100): response = self.get("/games", {key_type: lookup_keys_chunk}) # using a response map means we don't rely on twitch returning the data entries in the exact # order we requested them response_map = { response_entry[key_type]: response_entry for response_entry in response["data"] } # then fill in the gaps with None for lookup_key in lookup_keys_chunk: game_dict = response_map.get(lookup_key, None) if game_dict is None: all_entries.append(None) else: value: TwitchGame = TwitchGame( **response_map.get(lookup_key, None)) all_entries.append(value) return all_entries
def bulk_fetch_user_bans(self, key_type, lookup_keys, streamer_id, access_token): all_entries = {} # We can fetch a maximum of 100 users on each helix request # so we do it in chunks of 100 for lookup_keys_chunk in iterate_in_chunks(lookup_keys, 100): response = self.get("/moderation/banned", { "broadcaster_id": streamer_id, key_type: lookup_keys_chunk }, authorization=access_token) # using a response map means we don't rely on twitch returning the data entries in the exact # order we requested them response_map = { response_entry[key_type]: response_entry for response_entry in response["data"] } # then fill in the gaps with None for lookup_key in lookup_keys_chunk: all_entries[lookup_key] = response_map.get(lookup_key, None) return all_entries
def _bulk_fetch_user_data(self, key_type, lookup_keys): all_entries = [] # We can fetch a maximum of 100 users on each helix request # so we do it in chunks of 100 for lookup_keys_chunk in iterate_in_chunks(lookup_keys, 100): response = self.get("/users", {key_type: lookup_keys_chunk}) # using a response map means we don't rely on twitch returning the data entries in the exact # order we requested them response_map = {response_entry[key_type]: response_entry for response_entry in response["data"]} # then fill in the gaps with None for lookup_key in lookup_keys_chunk: all_entries.append(response_map.get(lookup_key, None)) return all_entries