def test_tosec_name(self): g = Game(name='Test') tosec_name = g.getTOSECName() self.assertTrue(tosec_name == 'Test (19xx)(-)') g.publisher = 'Something software' tosec_name = g.getTOSECName() self.assertTrue(tosec_name == 'Test (19xx)(Something software)') g.year = 1999 tosec_name = g.getTOSECName() self.assertTrue(tosec_name == 'Test (1999)(Something software)') g.setPublisher('16/48k Tape Magazine') self.assertEqual(g.getTOSECName(), 'Test (1999)(16-48k Tape Magazine)') g.setPublisher('Test [1]') self.assertEqual(g.getTOSECName(), 'Test (1999)(Test)') g.setPublisher('Test [test]') self.assertEqual(g.getTOSECName(), 'Test (1999)(Test)')
def getGames(self, sql_where='', sql_limit=9999999): sql = 'SELECT entries.id AS zxdb_id, ' \ 'releases.release_seq AS release_seq, ' \ 'entries.title AS name, ' \ 'entries.library_title AS tosec_compliant_name, ' \ 'entries.is_xrated AS x_rated, ' \ 'webrefs.link AS tipshop_page, ' \ 'genretypes.text AS genre, ' \ 'entries.max_players AS number_of_players, ' \ 'entries.idiom_id AS language, ' \ 'entries.availabletype_id AS availability, ' \ 'downloads.file_link AS file_link, ' \ 'downloads.file_size AS file_size, ' \ 'downloads.filetype_id AS file_type_id, ' \ 'downloads.idiom_id AS file_language, ' \ 'downloads.comments AS file_version, ' \ 'filetypes.text AS file_type, ' \ 'entry_machinetype.text AS machine_type, ' \ 'download_machinetype.text AS file_machine_type, ' \ 'schemetypes.text AS protection_scheme, ' \ 'releases.release_seq AS release_id, ' \ 'aliases.library_title AS alt_name, ' \ 'aliases.idiom_id AS alt_language, ' \ 'publisher_labels.name AS publisher, ' \ 'publisher_labels.labeltype_id AS publisher_type, ' \ 'author_labels.name AS author, ' \ 'author_labels.labeltype_id AS author_type, ' \ 'author_teams_labels.name AS author_team, ' \ 'author_teams_labels.labeltype_id AS author_team_type, ' \ 'releases.release_year AS year,' \ 'publisher_labels.country_id AS country ' \ 'FROM entries ' \ 'LEFT JOIN webrefs ON entries.id=webrefs.entry_id AND webrefs.website_id=9 ' \ 'LEFT JOIN releases ON entries.id=releases.entry_id ' \ 'LEFT JOIN downloads ON downloads.entry_id=entries.id AND downloads.release_seq=releases.release_seq ' \ 'LEFT JOIN publishers ON publishers.entry_id=entries.id AND publishers.release_seq=releases.release_seq ' \ 'LEFT JOIN labels AS publisher_labels ON publisher_labels.id=publishers.label_id ' \ 'LEFT JOIN authors ON authors.entry_id=entries.id ' \ 'LEFT JOIN labels AS author_labels ON author_labels.id=authors.label_id ' \ 'LEFT JOIN labels AS author_teams_labels ON author_teams_labels.id=authors.team_id ' \ 'LEFT JOIN aliases ON aliases.entry_id=entries.id AND aliases.release_seq=releases.release_seq ' \ 'LEFT JOIN filetypes ON downloads.filetype_id=filetypes.id ' \ 'LEFT JOIN genretypes ON genretypes.id=entries.genretype_id ' \ 'LEFT JOIN machinetypes download_machinetype ON download_machinetype.id=downloads.machinetype_id ' \ 'LEFT JOIN machinetypes entry_machinetype ON entry_machinetype.id=entries.machinetype_id ' \ 'LEFT JOIN schemetypes ON schemetypes.id=downloads.schemetype_id ' \ 'WHERE (entries.id>4000000 OR entries.id<2000000) AND ' \ '(downloads.filetype_id IS NULL OR downloads.filetype_id!=-1) and '\ '(authors.author_seq<=3 OR authors.author_seq IS NULL) ' if sql_where: sql += sql_where + ' ' sql +='ORDER BY zxdb_id, release_seq, entries.title IS NOT NULL ' \ 'LIMIT '+str(sql_limit) self.cur.execute(sql) game = Game() release = GameRelease() games = [] for row in self.cur: #Skipping ZX80/ZX81 files # print(row) if row['machine_type'] and row['machine_type'].startswith('ZX8'): continue if row['genre'] == 'Box Set': if row['zxdb_id'] in [8030]: row['genre'] = 'Compilation - Applications' elif row['zxdb_id'] in [11472]: row['genre'] = 'Compilation - Educational' else: row['genre'] = 'Compilation - Games' if row['publisher'] == 'Creative.Radical.Alternative.Production Games': row['publisher'] = 'Creative Radical Alternative Production Games' if row['author_team']: row['author'] = row['author_team'] row['author_type'] = row['author_team_type'] if row['zxdb_id'] and row[ 'name'] and row['zxdb_id'] != game.zxdb_id: game = self.gameFromRow(row) release = self.releaseFromRow(row, game) game.addRelease(release) games.append(game) if row['release_seq'] and row['release_seq'] != release.release_seq: release = self.releaseFromRow(row, game) game.addRelease(release) if release.release_seq == 0 and game.publisher and row[ 'publisher'] and game.raw_publisher and row[ 'publisher'] not in game.raw_publisher: game.raw_publisher.append(row['publisher']) publisher = self.publisherNameFromRow(row) publishers = game.publisher.split(' - ') publishers.append(publisher) game.publisher = ' - '.join(sorted(publishers, key=str.lower)) if release.publisher and row['publisher'] and row[ 'publisher'] not in release.raw_publisher: release.raw_publisher.append(row['publisher']) publisher = self.publisherNameFromRow(row) release_publishers = release.publisher.split(' - ') release_publishers.append(publisher) release.publisher = ' - '.join( sorted(release_publishers, key=str.lower)) if game.author and row['author'] and game.raw_author and row[ 'author'] not in game.raw_author: game.raw_author.append(row['author']) author = self.authorNameFromRow(row) authors = game.author.split(' - ') authors.append(author) game.author = ' - '.join(sorted(authors, key=str.lower)) if row['file_link'] and not (row['file_link'].endswith('.mlt')) and \ not row['file_link'].endswith('pdf') and not row['file_link'].endswith('.jpg'): if row['file_type'] == 'Loading screen': if row['file_link'].endswith('.gif'): if release.loading_screen_gif_filepath and \ release.loading_screen_gif_filepath!=row['file_link']: pass else: release.loading_screen_gif_filepath = row[ 'file_link'] release.loading_screen_gif_filesize = row[ 'file_size'] elif row['file_link'].endswith('scr'): if release.loading_screen_scr_filepath and \ release.loading_screen_scr_filepath!=row['file_link']: pass else: release.loading_screen_scr_filepath = row[ 'file_link'] release.loading_screen_scr_filesize = row[ 'file_size'] elif row['file_type'] == 'In-game screen': if row['file_link'].endswith('gif'): if release.ingame_screen_gif_filepath and \ release.ingame_screen_gif_filepath!=row['file_link']: pass else: release.ingame_screen_gif_filepath = row[ 'file_link'] release.ingame_screen_gif_filesize = row[ 'file_size'] elif row['file_link'].endswith('scr'): if release.ingame_screen_scr_filepath and \ release.ingame_screen_scr_filepath != row['file_link']: pass else: release.ingame_screen_scr_filepath = row[ 'file_link'] release.ingame_screen_scr_filesize = row[ 'file_size'] elif row['file_type'] == 'Instructions' and row[ 'file_link'].endswith('.txt'): if release.manual_filepath and \ release.manual_filepath!=row['file_link']: pass else: release.manual_filepath = row['file_link'] release.manual_filesize = row['file_size'] else: if row['publisher'] and \ ('Nyitrai' in row['publisher'] or 'Jatekgyaros' in row['publisher']) and \ row['genre'] and row['genre'] == 'Compilation': pass else: file_type = row['file_type'].lower() if 'snapshot' in file_type or \ 'disk' in file_type or \ 'tape' in file_type or \ 'rom' in file_type or \ 'covertape' in file_type or \ 'tr-dos' in file_type or \ 'electronic magazine' in file_type or \ 'cartridge' in file_type: game_file = self.gameFileFromRow(row, game) release.addFile(game_file) if row['alt_name'] and row['alt_language'] in (None, 'en'): alias = self.sanitizeAlias(row['alt_name']) release.addAlias(alias) games.append(game) return games