def _gather_information(self, game): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, game)) game_cache_path = self._set_up_path(os.path.join(self.api_cache, game)) file_path = os.path.join(game_cache_path, game+'.json') try: cp = ConfigParser.ConfigParser() cp.read(self.plugin.get_setting('api_key_file', str)) igdb_api_key = cp.get('API', 'igdb') except: xbmcgui.Dialog().notification( self.core().string('name'), self.core().string('scraper_failed') % (game, self.name()) ) return ApiResponse() url_opener = urllib2.build_opener() url_opener.addheaders = [ ('Accept', 'application/json'), ('Authorization', 'Token token=%s' % igdb_api_key) ] if not os.path.isfile(file_path): query_string = 'search?q=%s' % game response = url_opener.open(self.api_url % query_string) if response.getcode() in [200, 304]: search_results = json.load(url_opener.open(self.api_url % query_string)) print search_results if len(search_results) > 0: best_match_id = search_results['games'][0]['id'] else: return None else: raise IOError("Server failed with status code %s" % response.getcode()) else: best_match_id = None try: json_data = json.load(open(self._get_json_data(url_opener, game_cache_path, game, best_match_id))) except IOError: return None json_data = json_data['game'] api_response = ApiResponse() api_response.year = date_parser.parse(json_data['release_date']).year api_response.plot = json_data['summary'].encode('utf-8') for genre in json_data['genres']: api_response.genre.append(genre['name'].encode('utf-8')) if json_data['cover'] is not None: img_id = json_data['cover']['id'] cover_path = self._dump_image(game_cover_path, self.api_img_url % ('cover_big', img_id)) if cover_path is not None: api_response.posters.append(cover_path) return api_response
def _gather_information(self, nvapp, game): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, nvapp.id)) game_cache_path = self._set_up_path(os.path.join(self.api_cache, nvapp.id)) file_path = os.path.join(game_cache_path, game+'.json') try: cp = ConfigParser.ConfigParser() cp.read(self.plugin.get_setting('api_key_file', str)) igdb_api_key = cp.get('API', 'igdb') except: xbmcgui.Dialog().notification( self.core.string('name'), self.core.string('scraper_failed') % (game, self.name()) ) return ApiResponse() url_opener = urllib2.build_opener() url_opener.addheaders = [ ('Accept', 'application/json'), ('Authorization', 'Token token=%s' % igdb_api_key) ] if not os.path.isfile(file_path): query_string = 'search?q=%s' % game response = url_opener.open(self.api_url % query_string) if response.getcode() in [200, 304]: search_results = json.load(url_opener.open(self.api_url % query_string)) print search_results if len(search_results) > 0: best_match_id = search_results['games'][0]['id'] else: return None else: raise IOError("Server failed with status code %s" % response.getcode()) else: best_match_id = None try: json_data = json.load(open(self._get_json_data(url_opener, game_cache_path, game, best_match_id))) except IOError: return None json_data = json_data['game'] api_response = ApiResponse() api_response.year = date_parser.parse(json_data['release_date']).year api_response.plot = json_data['summary'].encode('utf-8') for genre in json_data['genres']: api_response.genre.append(genre['name'].encode('utf-8')) if json_data['cover'] is not None: img_id = json_data['cover']['id'] cover_path = self._dump_image(game_cover_path, self.api_img_url % ('cover_big', img_id)) if cover_path is not None: api_response.posters.append(cover_path) return api_response