コード例 #1
0
ファイル: types.py プロジェクト: baadjis/pokedex
def load_type_from_api(name):
    request = requests.get(f'https://pokeapi.co/api/v2/type/{name}')
    data = request.json()

    generation = Generation.get_or_none(name=data['generation']['name'])
    if generation is None:
        generation = Generation.create(name=data['generation']['name'])

    type = Type.get_or_none(name=data['name'])
    if type is None:
        type = Type.create(name=data['name'], generation=generation)

    return type
コード例 #2
0
ファイル: types.py プロジェクト: baadjis/pokedex
def get_type_by_name(query):

    if query is not None:
        query.lower()
        types = Type.select().where(query << Type.name)
        if len(types > 10):
            return (types[:10])
コード例 #3
0
ファイル: types.py プロジェクト: baadjis/pokedex
def add_type(name, generation_name):
    generation = Generation.get_or_none(Generation.name == generation_name)
    if generation is None:
        generation = Generation.create(name=generation_name)

    new_type = Type.create(name=name, generation=generation)
    return new_type
コード例 #4
0
ファイル: types.py プロジェクト: baadjis/pokedex
def get_types(search=None, unused=False):
    if search is None:
        search = ""

    types = []
    for type in Type.select().limit(10):
        if search in type.name:
            types.append(type)

    if unused:
        types = [type for type in types if len(type.pokemons) == 0]
    return types
コード例 #5
0
ファイル: pokemons.py プロジェクト: baadjis/pokedexold
def load_pokemon_types_from_api(name):
    request = requests.get(f'https://pokeapi.co/api/v2/pokemon/{name}')
    pokemon_data = request.json()

    pokemon = get_pokemon_by_name(name)
    PokemonTypes.delete().where(PokemonTypes.pokemon == pokemon).execute()

    types = []
    for api_type in pokemon_data['types']:
        type_name = api_type['type']['name']

        type = Type.get_or_none(name=type_name)
        if type is None:
            type = Type.create(name=type_name, url=api_type['type']['url'])

        pokemon_type = PokemonTypes.create(pokemon=pokemon,
                                           type=type,
                                           slot=api_type['slot'])

        types.append(pokemon_type)

    return types
コード例 #6
0
ファイル: pokemons.py プロジェクト: theomeb/strio-pokedex
def load_pokemon_types_from_api(name):
    request = requests.get(f"https://pokeapi.co/api/v2/pokemon/{name}")
    pokemon_data = request.json()

    pokemon = get_pokemon_by_name(name)
    PokemonTypes.delete().where(PokemonTypes.pokemon == pokemon).execute()

    types = []
    for api_type in pokemon_data["types"]:
        type_name = api_type["type"]["name"]

        type = Type.get_or_none(name=type_name)
        pokemon_type = PokemonTypes.create(pokemon=pokemon,
                                           type=type,
                                           slot=api_type["slot"])

        types.append(pokemon_type)

    return types
コード例 #7
0
ファイル: generation.py プロジェクト: Alexxxx35/Pokedex
def get_number_of_types_by_generation(generation=None):
    type_of_generation = Type.select().where(Type.generation == generation)
    number_of_types_of_generation = type_of_generation.count()
    return number_of_types_of_generation
コード例 #8
0
def get_type_name(name):
    type = Type.get_or_none(name=name)
    return type
コード例 #9
0
ファイル: generations.py プロジェクト: baadjis/pokedex
def number_of_Types(generation_id):
    counter = len(Type.select().where(Type.generation_id == generation_id))
    print(counter)
    return counter