def embed_pokemon(poke): species = poke.species descriptions = [] for entry in species.flavor_text_entries: if entry.language.name == 'en': descriptions.append(entry.flavor_text) types = sorted(list(poke.types), key=lambda x: x.slot) types = '/'.join(x.type.name.capitalize() for x in types) ability = random.choice(poke.abilities) known_moves = poke.moves random.shuffle(known_moves) known_moves = known_moves[:4] known_moves = [pb.NamedAPIResource('move', m.move.name) for m in known_moves] known_moves_str = [] for move in known_moves: for name in move.names: if name.language.name == 'en': known_moves_str.append(name.name) item = random_item() itemname = "" for name in item.names: if name.language.name == 'en': itemname = name.name break embed = Embed() embed.type = "rich" embed.color = Colour.blue() embed.title = "You caught: #{} {}".format(species.id, species.name.capitalize()) embed.description = random.choice(descriptions) embed.set_image( url=poke.sprites.front_default ) embed.add_field( name='Type', value=types ) embed.add_field( name='Ability', value=ability.ability.name.capitalize() ) embed.add_field( name='Moves', value=', '.join(known_moves_str) ) embed.add_field( name='Held item', value=itemname ) return embed
def get_pokemon_sprite(pokemon_id): sprite_url = pb.NamedAPIResource('pokemon', pokemon_id).sprites.front_default if sprite_url is None: print('No forward facing sprite found for id ' + str(pokemon_id) + "!") return None response = requests.get(sprite_url, stream=True) sprite = sqlite3.Binary(response.content) return sprite
def initail(self): self.dex = pb.NamedAPIResource('pokedex', 'kanto') #for the individual pokemon self.dict = self.dex.pokemon_entries num = len(self.dict) file = open('pokemon_entry.csv', 'w') file.write('name\n') for x in range(0, num): temp = (str(self.dict[x]).split("'name': '", 1)[1]) for j in str(temp): if j == "'": file.write('\n') break else: file.write(j) file.close() with open('pokemon_entry.csv') as csvfile: reader = csv.DictReader(csvfile) file = open('pokemon_dict.csv', 'w') file.write('name,' + 'height,' + 'weight,' + 'type1,' + 'type2,' + 'type3,' + 'type4,' + 'url\n') for z in reader: print('loading:' + z['name']) temp = pb.pokemon(z['name']) file.write(str(z['name']) + ',') file.write(str(temp.height) + ',') file.write(str(temp.weight) + ',') for j in range(0, 4): try: write = str(temp.types[j]).split("'name': '", 1)[1] for j in str(write): if j == "'": file.write(',') break else: file.write(j) except: file.write('0,') writeURL = str(temp.sprites).split("'front_default': '", 1)[1] for j in str(writeURL): if j == "'": break else: file.write(j) file.write('\n') print("loading Pokemons complete!")
def get_pokemon(pokemon_id): pokemon = pb.NamedAPIResource('pokemon', pokemon_id) # Get types as array types = [] for pokemon_type in pokemon.types: types.append(pokemon_type.type.name) # Get flavor text flavor_text = get_flavor_text(pokemon_id, pokemon.name) if flavor_text is None: raise Exception("Could not find flavor text!") # Return list of stats return pokemon.name, str(types), pokemon.height, pokemon.weight, flavor_text
def get_flavor_text(pokemon_id, name): pokemon_species = pb.NamedAPIResource('pokemon-species', pokemon_id) flavor_text_entries = pokemon_species.flavor_text_entries english_flavor_text_entries = [] flavor_text = "" # Get english entries for entry in flavor_text_entries: # Filter for english text if entry.language.name == 'en': # Remove line breaks, replace with space. Filter through duplicates where the pokemon name changes. filtered_flavor_text = str(entry.flavor_text).replace('\n', ' ').replace('\r', '').replace("\x0c", " ") filtered_flavor_text = filtered_flavor_text.replace(name, str(name).lower())\ .replace(str(name).upper(), str(name).lower()).replace(str(name).capitalize(), str(name).lower()) english_flavor_text_entries.append(filtered_flavor_text) # Delete repeated entries english_flavor_text_entries = list(dict.fromkeys(english_flavor_text_entries)) for entry in english_flavor_text_entries: flavor_text += entry + " " return flavor_text
async def pokemon(ctx): l = pb.APIResourceList('pokemon') poke = random.choice(list(l)) poke = pb.NamedAPIResource('pokemon', poke['name']) embed = embed_pokemon(poke) await bot.say(None, embed=embed)
def random_item(): l = pb.APIResourceList('item') item = random.choice(list(l)) return pb.NamedAPIResource('item', item['name'])
import pokebase as pb chesto = pb.NamedAPIResource('berry', 'chesto') print(chesto.name) print(chesto.natural_gift_type.name) charmander = pb.pokemon('charmander') print(charmander.height) print(charmander.abilities[1]) bulba = pb.pokemon_sprite(1) # And sprites too! print(bulba.path)