GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AmiiboAPI/checkfulldatabase.py at dev · 8bitDream/AmiiboAPI Expand file tree/ Copy pathcheckfulldatabase.pyMore file actions 296 lines (241 loc) · 9.19 KB / Copy pathcheckfulldatabase.pyFile metadata and controls296 lines (241 loc) · 9.19 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 #!/usr/bin/env python3 # coding=utf-8 import datetime import json import os import os.path import re # read the database with open('database/amiibo.json', encoding='utf-8-sig') as myfile: data = myfile.read() with open('database/games_info.json', encoding='utf-8-sig') as myfile: info = myfile.read() # parse database database = json.loads(data) game_info = json.loads(info) # compile the regex amiibo_series_regex = re.compile('^0x[0-9a-f]{2}') amiibo_regex = re.compile('^0x[0-9a-f]{16}$') character_regex = re.compile('^0x[0-9a-f]{4}') game_series_regex = re.compile('^0x[0-9a-f]{3}') types_regex = re.compile('^0x[0-9a-f]{2}') game_id_regex = re.compile('^[0-9A-F]{16}') date_regex = re.compile('^\d{4}-\d{2}-\d{2}') variant_regex = re.compile('^[0-9A-Fa-f]{8}$') # set success exit code exit_code = 0 used_amiibo_series = [] used_amiibo_character = [] used_amiibo_game_series = [] used_amiibo_types = [] warnings = [] errors = [] def printWarning(text): global warnings warnings.append('\033[1;33;40m' + text + '\x1b[0m') return def printError(code, text): global errors global exit_code exit_code = code errors.append('\033[1;31;40m' + text + '\x1b[0m') return def validateDate(date_text): try: datetime.datetime.strptime(date_text, '%Y-%m-%d') return True except ValueError: return False # check amiibos keys for key in database['amiibos']: if bool(amiibo_regex.match(key)): amiibo = database['amiibos'][key] character = '0x' + key[2:6] game_series = '0x' + key[2:5] amiibo_series = '0x' + key[14:16] type = '0x' + key[8:10] if character not in used_amiibo_character: used_amiibo_character.append(character) if game_series not in used_amiibo_game_series: used_amiibo_game_series.append(game_series) if amiibo_series not in used_amiibo_series: used_amiibo_series.append(amiibo_series) if type not in used_amiibo_types: used_amiibo_types.append(type) # check if game info exists if key not in game_info['amiibos']: printError(1, 'No game info for: ' + key) # check if name is set if 'name' not in amiibo: printError(1, 'Name not set for: ' + key) else: if amiibo['name'] == None: printError(1, 'Name not set for: ' + key) # check if release is set if 'release' in amiibo: release = amiibo['release'] if 'au' in release: if release['au'] is not None: if validateDate(release['au']) == False: printError(1, 'Formatting error on AU release for: ' + key) else: printWarning('AU release is null for: ' + key) else: printError(1, 'AU release not set for: ' + key) if 'eu' in release: if release['eu'] is not None: if validateDate(release['eu']) == False: printError(1, 'Formatting error on EU release for: ' + key) else: printWarning('EU release is null for: ' + key) else: printError(1, 'EU release not set for: ' + key) if 'jp' in release: if release['jp'] is not None: if validateDate(release['jp']) == False: printError(1, 'Formatting error on JP release for: ' + key) else: printWarning('\033[1;33;40mJP release is null for: ' + key) else: printError(1, 'JP release not set for: ' + key) if 'na' in release: if release['na'] is not None: if validateDate(release['na']) == False: printError(1, 'Formatting error on NA release for: ' + key) else: printWarning('NA release is null for: ' + key) else: printError(1, 'NA release not set for: ' + key) else: printError(1, 'Release not set for: ' + key) if 'variant' in amiibo: if amiibo['variant'] is not None and (not isinstance(amiibo['variant'], str) or bool(variant_regex.match(amiibo['variant'])) == False): printError(1, 'Formatting error on variant for: ' + key) # check if corresponding amiibo_series key exists if amiibo_series not in database['amiibo_series']: printError(1, 'Unknown amiibo series: ' + amiibo_series) # check if corresponding characters key exists if character not in database['characters']: printError(1, 'Unknown character: ' + character) # check if corresponding game_series key exists if game_series not in database['game_series']: printError(1, 'Unknown game series: ' + game_series) # check if corresponding types key exists if type not in database['types']: printError(1, 'Unknown type: ' + type) # check if corresponding icon file exists if not os.path.isfile('images/icon_' + key[2:10] + '-' + key[10:18] + '.png'): printError(1, 'Missing icon for: ' + key) else: printError(1, 'Formatting error on amiibo key: ' + key) # check machine keys if 'machine' in database: for key in database['machine']: if bool(amiibo_regex.match(key)): machine = database['machine'][key] if 'name' not in machine: printError(1, 'Machine name not set for: ' + key) else: if machine['name'] == None: printError(1, 'Machine name not set for: ' + key) else: printError(1, 'Formatting error on machine key: ' + key) # check amiibo_series keys for key in database['amiibo_series']: if bool(amiibo_series_regex.match(key)) == False: printError(1, 'Formatting error on amiibo series key: ' + key) else: if key not in used_amiibo_series: printError(1, 'Extraneous amiibo series: ' + key) # check characters keys for key in database['characters']: if bool(character_regex.match(key)) == False: printError(1, 'Formatting error on amiibo character key: ' + key) else: if key not in used_amiibo_character: printError(1, 'Extraneous amiibo character: ' + key) # check game_series keys for key in database['game_series']: if bool(game_series_regex.match(key)) == False: printError(1, 'Formatting error on amiibo game series key: ' + key) else: if key not in used_amiibo_game_series: printError(1, 'Extraneous amiibo game series: ' + key) # check types keys for key in database['types']: if bool(types_regex.match(key)) == False: printError(1, 'Formatting error on amiibo type key: ' + key) else: if key not in used_amiibo_types: printError(1, 'Extraneous amiibo type: ' + key) def validateGamePlatform(platform, key): global game_info game = game_info['amiibos'][key] if platform in game: game_3ds = game[platform] if game_3ds is not None: for info_key in range(len(game_3ds)): info = game_3ds[info_key] if info is not None: if 'amiiboUsage' in info: if info['amiiboUsage'] is not None: for amiibo_usage_key in range(len(info['amiiboUsage'])): amiibo_usage = info['amiiboUsage'][amiibo_usage_key] if amiibo_usage is not None: if 'Usage' in amiibo_usage: if amiibo_usage['Usage'] is None: printError(1, platform + '[' + str(info_key) + '][\'amiiboUsage\'][' + str(amiibo_usage_key) + '][\'Usage\'] is null for: ' + key) else: printError(1, 'Missing ' + platform + '[' + str(info_key) + '][\'amiiboUsage\'][' + str(amiibo_usage_key) + '][\'Usage\'] for: ' + key) if 'write' in amiibo_usage: if amiibo_usage['write'] is None: printError(1, platform + '[' + str(info_key) + '][\'amiiboUsage\'][' + str(amiibo_usage_key) + '][\'write\'] is null for: ' + key) else: printError(1, 'Missing ' + platform + '[' + str(info_key) + '][\'amiiboUsage\'][' + str(amiibo_usage_key) + '][\'write\'] for: ' + key) else: printError(1, platform + '[' + str(info_key) + '][\'amiiboUsage\'][' + str(amiibo_usage_key) + '] is null for: ' + key) else: printError(1, 'Missing ' + platform + '[' + str(info_key) + '][\'amiiboUsage\'] for: ' + key) if 'gameID' in info: if info['gameID'] is not None: for game_id_key in range(len(info['gameID'])): game_id = info['gameID'][game_id_key] if game_id is not None: if bool(game_id_regex.match(game_id)) == False: printError(1, 'Formatting error on ' + platform + '[' + str(info_key) + '][\'gameID\'][' + str(game_id_key) + '] (' + game_id + '): ' + key) else: printError(1, platform + '[' + str(info_key) + '][\'gameID\'][' + str(game_id_key) + '] is null for: ' + key) else: printError(1, 'Missing ' + platform + '[' + str(info_key) + '][\'gameID\'] for: ' + key) if 'gameName' in info: if info['gameName'] is None: printError(1, platform + '[' + str(info_key) + '][\'gameName\'] is null for: ' + key) else: printError(1, 'Missing ' + platform + '[' + str(info_key) + '][\'gameName\'] for: ' + key) else: printError(1, platform + '[' + str(info_key) + '] is null for: ' + key) else: printError(1, platform + ' is null for: ' + key) else: printError(1, 'Missing ' + platform + ' for: ' + key) # check game info keys for key in game_info['amiibos']: if bool(amiibo_regex.match(key)): game = game_info['amiibos'][key] if key not in database['amiibos']: printError(1, 'Extraneous game info for: ' + key) validateGamePlatform('games3DS', key) validateGamePlatform('gamesWiiU', key) validateGamePlatform('gamesSwitch', key) validateGamePlatform('gamesSwitch2', key) else: printError(1, 'Formatting error on game info key: ' + key) warnings = list(set(warnings)) warnings.sort() for warning in warnings: print(warning, flush=True) errors = list(set(errors)) errors.sort() for error in errors: print(error, flush=True) os._exit(exit_code) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |