def collection( self, collection_id, category_id=None, results=None, page=None, age=None, detailed=False, ): """Sends a POST request and fetches a list of applications belonging to the collection and an optional category. :param collection_id: the collection id, e.g. 'NEW_FREE'. :param category_id: (optional) the category id, e.g. 'GAME_ACTION'. :param results: the number of apps to retrieve at a time. :param page: page number to retrieve; limitation: page * results <= 500. :param age: an age range to filter by (only for FAMILY categories) :param detailed: if True, sends request per app for its full detail :return: a list of app dictionaries """ if collection_id not in COLLECTIONS and not collection_id.startswith( "promotion"): raise ValueError("Invalid collection_id '{collection}'.".format( collection=collection_id)) collection_name = COLLECTIONS.get(collection_id) or collection_id category = "" if category_id is None else CATEGORIES.get(category_id) if category is None: raise ValueError("Invalid category_id '{category}'.".format( category=category_id)) results = s.NUM_RESULTS if results is None else results if results > 120: raise ValueError("Number of results cannot be more than 120.") page = 0 if page is None else page if page * results > 500: raise ValueError( "Start (page * results) cannot be greater than 500.") if category.startswith("FAMILY") and age is not None: self.params["age"] = AGE_RANGE[age] url = build_collection_url(category, collection_name) data = generate_post_data(results, page) response = send_request("POST", url, data, self.params) if detailed: apps = self._parse_multiple_apps(response) else: soup = BeautifulSoup(response.content, "lxml", from_encoding="utf8") apps = [ parse_card_info(app_card) for app_card in soup.select('div[data-uitype="500"]') ] return apps
def collection(self, collection_id, category_id=None, results=None, page=None, age=None, detailed=False): """Sends a POST request and fetches a list of applications belonging to the collection and an optional category. :param collection_id: the collection id, e.g. 'NEW_FREE'. :param category_id: (optional) the category id, e.g. 'GAME_ACTION'. :param results: the number of apps to retrieve at a time. :param page: page number to retrieve; limitation: page * results <= 500. :param age: an age range to filter by (only for FAMILY categories) :param detailed: if True, sends request per app for its full detail :return: a list of app dictionaries """ if (collection_id not in COLLECTIONS and not collection_id.startswith('promotion')): raise ValueError('Invalid collection_id \'{collection}\'.'.format( collection=collection_id)) collection_name = COLLECTIONS.get(collection_id) or collection_id category = '' if category_id is None else CATEGORIES.get(category_id) if category is None: raise ValueError('Invalid category_id \'{category}\'.'.format( category=category_id)) results = s.NUM_RESULTS if results is None else results if results > 120: raise ValueError('Number of results cannot be more than 120.') page = 0 if page is None else page if page * results > 500: raise ValueError('Start (page * results) cannot be greater than 500.') if category.startswith('FAMILY') and age is not None: self.params['age'] = AGE_RANGE[age] url = build_collection_url(category, collection_name) data = generate_post_data(results, page) response = send_request('POST', url, data, self.params) if detailed: apps = self._parse_multiple_apps(response) else: soup = BeautifulSoup(response.content, 'lxml', from_encoding='utf8') apps = [parse_card_info(app_card) for app_card in soup.select('div[data-uitype="500"]')] return apps
def collection(self, collection_id, category_id=None, results=None, page=None, age=None, detailed=False): if (collection_id not in COLLECTIONS and not collection_id.startswith('promotion')): raise ValueError('Invalid collection_id \'{collection}\'.'.format( collection=collection_id)) collection_name = COLLECTIONS.get(collection_id) or collection_id category = '' if category_id is None else CATEGORIES.get(category_id) if category is None: raise ValueError('Invalid category_id \'{category}\'.'.format( category=category_id)) results = s.NUM_RESULTS if results is None else results if results > 120: raise ValueError('Number of results cannot be more than 120.') page = 0 if page is None else page if page * results > 500: raise ValueError( 'Start (page * results) cannot be greater than 500.') if category.startswith('FAMILY') and age is not None: self.params['age'] = AGE_RANGE[age] url = build_collection_url(category, collection_name) data = generate_post_data(results, page) response = send_request('POST', url, data, self.params) if detailed: apps = self._parse_multiple_apps(response) else: soup = BeautifulSoup(response.content, 'lxml', from_encoding='utf8') apps = [ parse_card_info(app_card) for app_card in soup.select('div[data-uitype="500"]') ] return apps