def developer(self, developer, results=None, page=None, detailed=False): """Sends a POST request and retrieves a list of the developer's published applications on the Play Store. :param developer: developer name to retrieve apps from, e.g. 'Disney' :param results: the number of app results to retrieve :param page: the page number to retrieve :param detailed: if True, sends request per app for its full detail :return: a list of app dictionaries """ if not isinstance(developer, basestring) or developer.isdigit(): raise ValueError('Parameter \'developer\' must be the developer name, not the developer id.') results = s.DEV_RESULTS if results is None else results page = 0 if page is None else page page_num = (results // 20) * page if not 0 <= page_num <= 12: raise ValueError('Page out of range. (results // 20) * page must be between 0 - 12') pagtok = self._pagtok[page_num] url = build_url('developer', developer) data = generate_post_data(results, 0, pagtok) 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) for app in soup.select('div[data-uitype="500"]')] return apps
def details(self, app_id): """Sends a GET request and parses an application's details. :param app_id: the app to retrieve details, e.g. 'com.nintendo.zaaa' :return: a dictionary of app details """ url = build_url('details', app_id) try: response = send_request('GET', url, params=self.params) soup = BeautifulSoup(response.content, 'lxml', from_encoding='utf8') except requests.exceptions.HTTPError as e: raise ValueError('Invalid application ID: {app}. {error}'.format( app=app_id, error=e)) app_json = parse_app_details(soup) app_json.update({ 'app_id': app_id, 'url': url, }) return app_json
def similar(self, app_id, detailed=False, **kwargs): """Sends a GET request, follows the redirect, and retrieves a list of applications similar to the specified app. :param app_id: app to retrieve details from, e.g. 'com.nintendo.zaaa' :param detailed: if True, sends request per app for its full detail :return: a list of similar apps """ url = build_url('similar', app_id) response = send_request('GET', url, params=self.params, allow_redirects=True) soup = BeautifulSoup(response.content, 'lxml', from_encoding='utf8') if detailed: apps = self._parse_multiple_apps(response) else: apps = [parse_card_info(app) for app in soup.select('div[data-uitype="500"]')] return apps
def similar(self, app_id, detailed=False, **kwargs): """Sends a GET request, follows the redirect, and retrieves a list of applications similar to the specified app. :param app_id: app to retrieve details from, e.g. 'com.nintendo.zaaa' :param detailed: if True, sends request per app for its full detail :return: a list of similar apps """ url = build_url('similar', app_id) response = send_request('GET', url, params=self.params, allow_redirects=True) soup = BeautifulSoup(response.content, 'lxml', from_encoding='utf8') if detailed: apps = self._parse_multiple_apps(response) else: apps = [ parse_card_info(app) for app in soup.select('div[data-uitype=500]') ] return apps
def test_building_multiple_word_dev_name(self): expected = "https://play.google.com/store/apps/developer?id=SQUARE+ENIX+INC" self.assertEqual(expected, build_url("developer", "SQUARE ENIX INC"))
def test_building_simple_dev_name(self): expected = "https://play.google.com/store/apps/developer?id=Disney" self.assertEqual(expected, build_url("developer", "Disney"))
def test_building_app_url(self): expected = "https://play.google.com/store/apps/details?id=com.facebook.orca" self.assertEqual(expected, build_url("details", "com.facebook.orca"))
def test_building_multiple_word_dev_name(self): expected = 'https://play.google.com/store/apps/developer?id=SQUARE+ENIX+INC' self.assertEqual(build_url('developer', 'SQUARE ENIX INC'), expected)
def test_building_simple_dev_name(self): expected = 'https://play.google.com/store/apps/developer?id=Disney' self.assertEqual(build_url('developer', 'Disney'), expected)
def test_building_app_url(self): expected = 'https://play.google.com/store/apps/details?id=com.facebook.orca' self.assertEqual(build_url('details', 'com.facebook.orca'), expected)