def getListingsById(self, listing_ids, use_cache=False): ''' Populate this object with the listings for a list of IDs :param listing_ids: The list of IDs to query for. ''' # This section handles getting any cached entries, and pruning the query id list if so cached_results = [] if use_cache: cached_ids = [listing_id for listing_id in listing_ids if int(listing_id) in self.listings] cached_results = [self.listings[int(listing_id)] for listing_id in cached_ids] listing_ids = list(set(listing_ids) - set(cached_ids)) # This section gets any ids in the id list from the API. if listing_ids: raw_listings = util.idListApiCall('/v2/commerce/listings?ids=', listing_ids) for raw_listing in raw_listings: self._indexListing(ItemListings(raw_listing)) return cached_results + [self.listings[int(listing_id)] for listing_id in listing_ids if int(listing_id) in self.listings]
def getItemsById(self, item_ids, use_cache=False): ''' Populate this object with the items for a list of IDs :param item_ids: The list of IDs to query for. ''' # This section handles getting any cached entries, and pruning the query id list if so cached_results = [] if use_cache: cached_ids = [item_id for item_id in item_ids if int(item_id) in self.items] cached_results = [self.items[int(item_id)] for item_id in cached_ids] item_ids = list(set(item_ids) - set(cached_ids)) # This gets any ids left in the item_ids list from the api. if item_ids: raw_items = util.idListApiCall('/v2/items?ids=', item_ids) for raw_item in raw_items: self._indexItem(Item(raw_item)) # We return both cached and uncached together return cached_results + [self.items[int(item_id)] for item_id in item_ids if int(item_id) in self.items]