def test_jsonOld1(self): # testing "old php api" call. Use an actual old result as sample data = json.load(open('../oldApiSample.json')) blues = [] reds = [] limit = len(data['blue']) for i, p in enumerate(data['blue'] + data['red']): pkmn = {} t2 = p['type2'] if p['type2'] != '-' else None gender = Gender.none if p['gender'] == 'm': gender = Gender.male elif p['gender'] == 'f': gender = Gender.female pkmn = self.genPkmn(name=p['name'], id=p['id'], type1=p['type1'], type2=t2, gender=gender, ability=p['ability'], stats=self.genStats(p['stats']['hp'], p['stats']['atk'], p['stats']['def'], p['stats']['satk'], p['stats']['sdef'], p['stats']['spd'])) pkmn.moves = [] for m in p['moves']: category = MoveCategory.nonDamaging if m['category'] == 'physical': category = MoveCategory.physical elif m['category'] == 'special': category = MoveCategory.special elif m['category'] == 'ohko': category = MoveCategory.physical accuracy = m['accuracy'] if m['accuracy'] > 0 else None pkmn.moves.append(self.genMove(name=m['name'], type=m['type'], pp=m['pp'], power=m.get('power', None), accuracy=accuracy, category=category)) (blues if i < limit else reds).append(pkmn) json.dump(buildDictOldApi(blues, reds, self.genEnv(weather='none')), open('../test.json', 'w+'), indent=4)
def handleRequest(data, sock): match = re.match(b'GET /visu/([0-9,]+)/([0-9,]+)\sHTTP/1', data) if match: blueIDs = [int(ID) for ID in match.group(1).split(b',')] redIDs = [int(ID) for ID in match.group(2).split(b',')] # TODO replace these 2 lines with the actual pokemon data retrieved from the IDs # They need to be packed into the visualizer's own Pokemon objects blues = [ Pokemon(1, 'A', 'fire', None, Stats(50, 60, 70, 80, 90, 100), [Move('Tackle', '', 'normal', 1, 70, 10, 90)], 0, '') ] reds = [ Pokemon(2, 'B', 'water', None, Stats(50, 60, 70, 80, 90, 100), [Move('Tackle', '', 'normal', 1, 70, 10, 90)], 0, '') ] result = buildDictOldApi(blues, reds, Environment(weather='none')) sock.sendall(b"""HTTP/1.1 200 OK Cache-Control: no-cache, must-revalidate Expires: Mon, 26 Jul 1997 05:00:00 GMT Access-Control-Allow-Origin: * Connection: close Content-Type: application/json """ + json.dumps(result, indent=4).encode('ascii') ) # For Python3: indent=' ' or something. else: sock.sendall(b"""HTTP/1.1 404 Not Found Connection: close """)
def test_jsonOld1(self): # testing "old php api" call. Use an actual old result as sample data = json.load(open('../oldApiSample.json')) blues = [] reds = [] limit = len(data['blue']) for i, p in enumerate(data['blue'] + data['red']): pkmn = {} t2 = p['type2'] if p['type2'] != '-' else None gender = Gender.none if p['gender'] == 'm': gender = Gender.male elif p['gender'] == 'f': gender = Gender.female pkmn = self.genPkmn( name=p['name'], id=p['id'], type1=p['type1'], type2=t2, gender=gender, ability=p['ability'], stats=self.genStats(p['stats']['hp'], p['stats']['atk'], p['stats']['def'], p['stats']['satk'], p['stats']['sdef'], p['stats']['spd'])) pkmn.moves = [] for m in p['moves']: category = MoveCategory.nonDamaging if m['category'] == 'physical': category = MoveCategory.physical elif m['category'] == 'special': category = MoveCategory.special elif m['category'] == 'ohko': category = MoveCategory.physical accuracy = m['accuracy'] if m['accuracy'] > 0 else None pkmn.moves.append( self.genMove(name=m['name'], type=m['type'], pp=m['pp'], power=m.get('power', None), accuracy=accuracy, category=category)) (blues if i < limit else reds).append(pkmn) json.dump(buildDictOldApi(blues, reds, self.genEnv(weather='none')), open('../test.json', 'w+'), indent=4)
def handleRequest(data, sock): match = re.match(b'GET /visu/([0-9,]+)/([0-9,]+)\sHTTP/1', data) if match: blueIDs = [int(ID) for ID in match.group(1).split(b',')] redIDs = [int(ID) for ID in match.group(2).split(b',')] # TODO replace these 2 lines with the actual pokemon data retrieved from the IDs # They need to be packed into the visualizer's own Pokemon objects blues = [Pokemon(1, 'A', 'fire', None, Stats(50, 60, 70, 80, 90, 100), [Move('Tackle', '', 'normal', 1, 70, 10, 90)], 0, '')] reds = [Pokemon(2, 'B', 'water', None, Stats(50, 60, 70, 80, 90, 100), [Move('Tackle', '', 'normal', 1, 70, 10, 90)], 0, '')] result = buildDictOldApi(blues, reds, Environment(weather='none')) sock.sendall(b"""HTTP/1.1 200 OK Cache-Control: no-cache, must-revalidate Expires: Mon, 26 Jul 1997 05:00:00 GMT Access-Control-Allow-Origin: * Connection: close Content-Type: application/json """ + json.dumps(result, indent=4).encode('ascii')) # For Python3: indent=' ' or something. else: sock.sendall(b"""HTTP/1.1 404 Not Found Connection: close """)