def gog_id_exists(self, gog_id): db = sqlite3.connect(self.dataFile) c = db.cursor() c.execute( 'SELECT title, description, run_platforms, genres, store, storepage, steam_appid, gog_id, game_internal_id, category_id from games where gog_id = ?', (gog_id, )) games_raw = c.fetchall() c.close() if (games_raw and len(games_raw) > 0): g = games_raw[0] game = Game(g[0], g[1], g[2], g[3], g[4], g[5], g[6], g[7], g[8]) game.set_category(g[9]) return game else: return None
def on_ok(self): #platforms = self.gameplatforms._contained_widget.get_selected_objects(self.gameplatforms); if not self.gametitle.value: npyscreen.notify_confirm("Title is required", "Error") else: platformString = "" #all_platforms = self.parentApp.gamedata.platforms; platform_selections = self.gameplatforms._contained_widget.get_selected_objects( self.gameplatforms) if (platform_selections and len(platform_selections) > 0): for pselection in platform_selections: platformString += str(pselection.platform_id) + "," storesString = "" stores_selections = self.gamestores._contained_widget.get_selected_objects( self.gamestores) if (stores_selections and len(stores_selections) > 0): for sselection in stores_selections: storesString += str(sselection.store_id) + "," description = '\n'.join(self.gamedescription.values) storepage = self.gamestorepage.value genres = self.unique(self.gamegenre.values) genres = '\n'.join(genres) category = self.gamecategory._contained_widget.get_selected_objects( self.gamecategory)[0].category_id if (not self.value): game = Game(self.gametitle.value, description, platformString, genres, storesString, storepage, None, None, None) game.set_category(category - 1) self.parentApp.gamedata.add_game(game) else: game_old = self.value game_new = Game(self.gametitle.value, description, platformString, genres, storesString, storepage, game_old.steam_appid, game_old.gog_id, game_old.record_id) game_new.set_category(category - 1) self.parentApp.gamedata.update_game(game_new) self.parentApp.gamedata.load_games() self.parentApp.switchFormPrevious()
def load_games(self, ): db = sqlite3.connect(self.dataFile) c = db.cursor() c.execute( 'SELECT title, description, run_platforms, genres, store, storepage, steam_appid, gog_id, game_internal_id, category_id, created_at, updated_at from games ORDER BY title ASC' ) games_raw = c.fetchall() c.close() games_new = [] for g in games_raw: new_game = Game(g[0], g[1], g[2], g[3], g[4], g[5], g[6], g[7], g[8]) new_game.set_category(g[9]) new_game.set_created(g[10]) new_game.set_updated(g[11]) games_new.append(new_game) self.games = games_new
def gog_update(self, platforms, store_id): media_type = GOG_MEDIA_TYPE_GAME items = [] i = 0 self.load_cookies() api_url = GOG_ACCOUNT_URL api_url += "/getFilteredProducts" done = False while not done: i += 1 url = api_url + "?" + urlencode({'mediaType': media_type, 'sortBy': 'title', 'page': str(i)}) with self.request(url, delay=0) as data_request: reader = codecs.getreader("utf-8") try: json_data = json.load(reader(data_request)) except ValueError: raise SystemExit(1) for item_json_data in json_data['products']: if item_json_data.get('isHidden', False) is True: continue gog_id = str(item_json_data['id']) title = item_json_data['title'] description = item_json_data['slug'] genre = item_json_data['category'] store_url = "https://www.gog.com" + item_json_data['url'] src_platforms = item_json_data['worksOn'] run_platforms = [] for platform in platforms: key = platform.name.lower() if('linux' in key): key = 'linux' if('mac' in key): key = 'mac' lower_src_platforms = dict( (k.lower(), v) for k, v in src_platforms.items()) if(key in lower_src_platforms): if lower_src_platforms[key]: run_platforms.append(str(platform.platform_id)) run_platforms = ','.join(run_platforms) game = Game(title, description, run_platforms, genre, store_id, store_url, None, gog_id, None) game.set_category(0) items.append(game) if i >= json_data['totalPages']: done = True return items
def run(self): while self.thread_run: content = self.get_games() total_count = content["total_count"] games = content["games"] current_count = 0 for meta_game in games: current_count = current_count + 1 temp_game = self.get_game(meta_game["appid"]) if(not temp_game): continue title = temp_game['name'] description = temp_game['short_description'] src_platforms = temp_game['platforms'] platforms = self.gamedata.platforms run_platforms = [] for platform in platforms: key = platform.name.lower() if('linux' in key): key = 'linux' if('mac' in key): key = 'mac' if(key in src_platforms): if src_platforms[key]: run_platforms.append(str(platform.platform_id)) run_platforms = ','.join(run_platforms) genres = [] if('genres' in temp_game): src_genres = temp_game['genres'] for genre in src_genres: if ('description' in genre): genres.append(genre['description']) if('categories' in temp_game): src_categories = temp_game['categories'] for category in src_categories: genres.append(category['description']) genres = '\n'.join(genres) # Get steam store = "" for st in self.gamedata.stores: if(st.name.lower() == 'steam'): store = st.store_id # create steampage: storepage = 'https://store.steampowered.com/app/' + \ str(meta_game["appid"]) steam_appid = str(meta_game["appid"]) game = Game(title, description, run_platforms, genres, store, storepage, steam_appid, None, None) game.set_category(0) record = self.gamedata.steam_appid_exists(steam_appid) if(record): game.record_id = record.record_id game.set_category(record.category); self.gamedata.update_game(game) else: self.gamedata.add_game(game) percentage = (current_count / total_count) * 100 self.loader.set_value(percentage) self.loader.update() self.refresh() self.thread_run = False