Example #1
0
def load_pokemon_species_from_api(name):
    request = requests.get(f'https://pokeapi.co/api/v2/pokemon-species/{name}')
    data = request.json()

    species = PokemonSpecies.get_or_none(name=name)
    if species is None:
        db_data = {
            'name': data['name'],
            'order': data['order'],
            'gender_rate': data['gender_rate'],
            'capture_rate': data['capture_rate'],
            'base_happiness': data['base_happiness'],
            'is_baby': data['is_baby']
        }
        species = PokemonSpecies.create(**db_data)

    PokemonSpeciesEggGroups.delete().where(
        PokemonSpeciesEggGroups.pokemon_species == species).execute()
    for api_egg_group in data['egg_groups']:
        egg_group = EggGroup.get_or_none(name=api_egg_group['name'])
        PokemonSpeciesEggGroups.create(pokemon_species=species,
                                       egg_group=egg_group)

    PokemonSpeciesVariety.delete().where(
        PokemonSpeciesVariety.pokemon_species == species).execute()
    for variety in data['varieties']:
        pokemon = Pokemon.get_or_none(name=variety['pokemon']['name'])
        PokemonSpeciesVariety.create(pokemon_species=species,
                                     is_default=variety['is_default'],
                                     pokemon=pokemon)

    return species
Example #2
0
def get_species(egg_group=None, limit=None):
    species = PokemonSpecies.select().limit(limit)

    if egg_group is not None:
        egg_group = EggGroup.get_or_none(name=egg_group)
        if egg_group is not None:
            species = species.join(PokemonSpeciesEggGroups).where(PokemonSpeciesEggGroups.egg_group == egg_group)

    return species
Example #3
0
def get_specie(specie_id):
    specie = PokemonSpecies.get_or_none(id=specie_id)
    if specie is None:
        raise SpecieNotFoundError(specie_id)
    return specie
Example #4
0
def get_specie(specie_id):
    specie = PokemonSpecies.get_or_none(id=specie_id)
    return specie