Пример #1
0
def create_pokemon(name, hp, special_attack, defense, attack, special_defense, speed):
    stats = {'hp': hp, 'special_attack': special_attack, 'defense': defense,
             'attack': attack, 'special_defense': special_defense,
             'speed': speed}
    try:
        pokemon = get_pokemon_by_name(name)
        update_model_from_dict(pokemon, stats)
        pokemon.save()
    except PokemonNotFoundError:
        pokemon = Pokemon.create(name=name, **stats)

    return pokemon
Пример #2
0
def create_pokemon(name, hp, special_attack, defense, attack, special_defense,
                   speed):
    stats = {
        'hp': hp,
        'special_attack': special_attack,
        'defense': defense,
        'attack': attack,
        'special_defense': special_defense,
        'speed': speed
    }
    pokemon = Pokemon.get_or_none(name=name)
    if pokemon is None:
        pokemon = Pokemon.create(name=name, **stats)

    return pokemon
Пример #3
0
def create_pokemon(name, hp, special_attack, defense, attack, special_defense,
                   speed):
    stats = {
        "hp": hp,
        "special_attack": special_attack,
        "defense": defense,
        "attack": attack,
        "special_defense": special_defense,
        "speed": speed,
    }
    try:
        pokemon = get_pokemon_by_name(name)
        update_model_from_dict(pokemon, stats)
        pokemon.save()
    except PokemonNotFoundError:
        pokemon = Pokemon.create(name=name, **stats)

    return pokemon
Пример #4
0
def load_pokemon_from_api(name):
    request = requests.get(f'https://pokeapi.co/api/v2/pokemon/{name}')
    pokemon_data = request.json()

    stats = {}
    for stat in pokemon_data['stats']:
        stat_name = stat['stat']['name'].replace('-', '_')
        stat_value = int(stat['base_stat'])

        stats[stat_name] = stat_value

    sprite_front = pokemon_data['sprites']['front_default']
    sprite_back = pokemon_data['sprites']['back_default']

    pokemon = Pokemon.get_or_none(name=name)
    data = {'sprite_front': sprite_front, 'sprite_back': sprite_back, **stats}
    if pokemon is None:
        pokemon = Pokemon.create(name=name, **data)
    else:
        update_model_from_dict(pokemon, data)
        pokemon.save()

    return pokemon
Пример #5
0
def load_pokemon_from_api(name):
    request = requests.get(f"https://pokeapi.co/api/v2/pokemon/{name}")
    pokemon_data = request.json()

    stats = {}
    for stat in pokemon_data["stats"]:
        stat_name = stat["stat"]["name"].replace("-", "_")
        stat_value = int(stat["base_stat"])

        stats[stat_name] = stat_value

    sprite_front = pokemon_data["sprites"]["front_default"]
    sprite_back = pokemon_data["sprites"]["back_default"]

    pokemon = Pokemon.get_or_none(name=name)
    data = {"sprite_front": sprite_front, "sprite_back": sprite_back, **stats}
    if pokemon is None:
        pokemon = Pokemon.create(name=name, **data)
    else:
        update_model_from_dict(pokemon, data)
        pokemon.save()

    return pokemon