def add_ability(name, generation_name): generation = Generation.get_or_none(Generation.name == generation_name) if generation is None: generation = Generation.create(name=generation_name) new_ability = Ability.create(name=name, generation=generation) return new_ability
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
def load_ability_from_api(name): request = requests.get(f'https://pokeapi.co/api/v2/ability/{name}') data = request.json() generation = Generation.get_or_none(name=data['generation']['name']) if generation is None: generation = Generation.create(name=data['generation']['name']) ability = Ability.get_or_none(name=name) if ability is None: db_data = { 'name': data['name'], 'is_main_series': data['is_main_series'], 'generation': generation } ability = Ability.create(**db_data) AbilityEffects.delete().where(AbilityEffects.ability == ability).execute() for effect in data['effect_entries']: verbose_effect = VerboseEffect.get_or_none( short_effect=effect['short_effect']) if verbose_effect is None: language = Language.get_or_none(name=effect['language']['name']) if language is None: language = Language.create(name=effect['language']['name']) verbose_effect = VerboseEffect.create( effect=effect['effect'], short_effect=effect['short_effect'], language=language) ability_effect = AbilityEffects.create(ability=ability, effect=verbose_effect) return ability
def get_generations(query=None): if query is not None: generations = Generation.select().where(Generation.name == query) else: generations = Generation.select() return generations
def get_abilities(generation=None, limit=None, offset=None): abilities = Ability.select().offset(offset).limit(limit) if generation is not None: generation_id = Generation.get_or_none(name=generation) if generation_id is not None: abilities = Generation.select().where( Generation.name == generation) return abilities
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
def get_abilities(search=None, unused=False, query_gerneration=None): abilities = [] if search is None: search = "" abilities = [] for ability in Ability.select().order_by(Ability.id): if search in ability.name: abilities.append(ability) if unused: abilities = [ ability for ability in abilities if len(ability.pokemons) == 0 ] if query_gerneration is not None: filtered_abilities = [] for ability in abilities: # abilities = [] generation_de_ce_ability = Generation.select().where( Generation.id == ability.generation) # print((generation_de_ce_ability[0].name)) if query_gerneration in generation_de_ce_ability[0].name: filtered_abilities.append(ability) abilities = filtered_abilities return abilities
def get_ability_generation_name(filter): ability_generation_name = Generation.select().join(Ability).join( AbilityEffects).join(VerboseEffect).where(Generation.name == filter) result = [] for ability in ability_generation_name: result.append(ability.get_small_data()) result_ab = result[0:10] return result_ab
def create_new_generation(generation_name): Generation.create(name=generation_name)
def get_generation_name(generation_id): generation = Generation.get_by_id(generation_id) return generation.name
def get_generations(query=None): generations = Generation.select(Generation.id, Generation.name) if query != None: generations = generations.where(query << Generation.name) return [dict(gen.get_small_data()) for gen in generations]
def create_generation(name): return Generation.get_or_create(name=name)
def get_generation(generation_name): generation, created = Generation.get_or_none(name=generation_name) return generation
def get_generations(): species = Generation.select() return species