예제 #1
0
    def create_multiple_pokemon_objects(cls, pokemon_name: list):
        """
        Creates multiple pokemon objects
        :param pokemon_name:
        :return: Pokemon
        """
        request = pokedex.setup_request_commandline()
        async_move = \
            asyncio.run(
                RequestApi.process_multiple_pokemon_requests(pokemon_name))
        string_convert = json.dumps(async_move)
        pokemon_convert_json = json.loads(string_convert)

        print("\n")
        for pokemon in pokemon_convert_json:
            pokemon_name = pokemon["name"]
            pokemon_id = pokemon["id"]
            pokemon_height = pokemon["height"]
            pokemon_weight = pokemon["weight"]
            stat_name = [item["stat"]["name"] for item in pokemon["stats"]]
            base_stat = [item["base_stat"] for item in pokemon["stats"]]

            pokemon_stats = list(zip(stat_name, base_stat))
            pokemon_type = [item["type"]["name"] for item in pokemon["types"]]
            pokemon_abilities = [
                item["ability"]["name"] for item in pokemon["abilities"]
            ]

            move = [item1["move"]["name"] for item1 in pokemon["moves"]]
            level = [
                item1["version_group_details"][0]["level_learned_at"]
                for item1 in pokemon["moves"]
            ]
            moves = list(zip(move, level))

            final_pokemon_object = Pokemon(pokemon_name, pokemon_id,
                                           pokemon_height, pokemon_weight,
                                           pokemon_stats, pokemon_type,
                                           pokemon_abilities, moves)
            if request[0].lower() == "pokemon" and request[3] is None:
                print(final_pokemon_object)
                print(f"{final_pokemon_object.name.title()} Stats:")
                for stats in final_pokemon_object.stats:
                    print(stats)
                print(f"\n{final_pokemon_object.name.title()} "
                      f"Moves and Level Learnt:")
                for move_, level in final_pokemon_object.moves:
                    print(f"{move_} learnt at {level}")
            if request[0].lower() == "pokemon" and request[3] is not None:
                with open(request[3], mode="a") \
                        as output_file:
                    output_file.write("\n")
                    output_file.write(str(final_pokemon_object))
                    output_file.write("Stats:")
                    for stats in final_pokemon_object.stats:
                        output_file.write(str(stats))
                    output_file.write("\nMoves and Level Learnt:")
                    for move_, level in final_pokemon_object.moves:
                        output_file.write("\n-" + str(move_) + " learnt at " +
                                          str(level))
예제 #2
0
    def create_multiple_move_objects(cls, move_name_: list):
        """
        Creates multiple Move objects into a list.
        :param move_name_:
        :return: Move : list
        """
        request = pokedex.setup_request_commandline()
        async_move = \
            asyncio.run(RequestApi.process_multiple_move_requests(move_name_))
        string_convert = json.dumps(async_move)
        moves_convert_json = json.loads(string_convert)

        print("\n")
        for move in moves_convert_json:
            move_name = move["name"]
            move_id = move["id"]
            move_gen = move["generation"]["name"]
            move_accuracy = move["accuracy"]
            move_pp = move["pp"]
            move_power = move["power"]
            move_type = move["type"]["name"]
            move_damage_class = move["damage_class"]["name"]
            move_short_effect = move["effect_entries"][0]["short_effect"]
            final_move_object = Moves(move_name, move_id, move_gen,
                                      move_accuracy, move_pp, move_power,
                                      move_type, move_damage_class,
                                      move_short_effect)
            if request[0].lower() == "move" and request[3] is None:
                print(final_move_object)
            if request[0].lower() == "move" and request[3] is not None:
                with open(request[3], mode="a") \
                        as output_file:
                    output_file.write(str(final_move_object))
예제 #3
0
    def create_multiple_ability_objects(cls, ability_name_: list):
        """
        Creates multiple ability objects.
        :param ability_name_:
        :return: Ability : list
        """
        request = pokedex.setup_request_commandline()
        async_move = \
            asyncio.run(
                RequestApi.process_multiple_ability_requests(ability_name_))
        string_convert = json.dumps(async_move)
        ability_convert_json = json.loads(string_convert)

        print("\n")
        for ability in ability_convert_json:
            ability_name = ability["name"]
            ability_id = ability["id"]
            ability_gen = ability["generation"]["name"]
            ability_long_effect = ability["effect_entries"][0]["effect"]
            ability_short_effect = ability["effect_entries"][0]["short_effect"]
            ability_pokemon = "\n-".join(
                [item["pokemon"]["name"] for item in ability["pokemon"]])

            final_ability_object = Ability(ability_name, ability_id,
                                           ability_gen, ability_long_effect,
                                           ability_short_effect,
                                           ability_pokemon)
            if request[0].lower() == "ability" and request[3] is None:
                print(final_ability_object)
            if request[0].lower() == "ability" and request[3] is not None:
                with open(request[3], mode="a") \
                        as output_file:
                    output_file.write(str(final_ability_object))
예제 #4
0
 def create_expanded_stats(cls, pokemon_name_1: str):
     """
     Expandes the stats of each Pokemon object using the Stats URL.
     :param pokemon_name_1:
     :return: Stats
     """
     request = pokedex.setup_request_commandline()
     stats_url = Pokemon.create_pokemon_object(pokemon_name_1)
     stats_url_list = stats_url[2]
     async_stats_expanded = \
         asyncio.run(
             RequestApi.expanded_process_multiple_pokemon_requests(
                 stats_url_list))
     stats_expanded_dump = json.dumps(async_stats_expanded)
     stats_expanded_query = json.loads(stats_expanded_dump)
     print("\n---------------"
           "EXPANDED STATS INCLUDED-----------------------------")
     for stat in stats_expanded_query:
         stat_name = stat["name"]
         stat_id = stat["id"]
         stat_is_battle_only = stat["is_battle_only"]
         final_stat_object = Stats(stat_name, stat_id, stat_is_battle_only)
         # print(final_stat_object)
         # print(request[2])
         if request[3] is None:
             print(final_stat_object)
         elif request[3] is not None:
             with open(request[3], mode="a") as output_file:
                 output_file.write("\n\n-----EXPANDED STAT-----\n")
                 output_file.write(str(final_stat_object))
예제 #5
0
 def create_expanded_moves(cls, pokemon_name_2: str):
     """
     Exapnds the moves of each Pokemon using the move URL. Crerates
     a move object.
     :param pokemon_name_2:
     :return: Move
     """
     request = pokedex.setup_request_commandline()
     moves_url = Pokemon.create_pokemon_object(pokemon_name_2)
     moves_url_list = moves_url[3]
     async_ability_expanded = \
         asyncio.run(
             RequestApi.expanded_process_multiple_pokemon_requests(
                 moves_url_list))
     ability_expanded_dump = json.dumps(async_ability_expanded)
     ability_expanded_query = json.loads(ability_expanded_dump)
     print("\n---------------EXPANDED MOVES INCLUDED----"
           "-------------------------")
     for move in ability_expanded_query:
         move_name = move["name"]
         move_id = move["id"]
         move_gen = move["generation"]["name"]
         move_accuracy = move["accuracy"]
         move_pp = move["pp"]
         move_power = move["power"]
         move_type = move["type"]["name"]
         move_damage_class = move["damage_class"]["name"]
         move_short_effect = move["effect_entries"][0]["short_effect"]
         final_move_object = Moves(move_name, move_id, move_gen,
                                   move_accuracy, move_pp, move_power,
                                   move_type, move_damage_class,
                                   move_short_effect)
         if request[3] is None:
             print(final_move_object)
         elif request[3] is not None:
             with open(request[3], mode="a") as output_file:
                 output_file.write("\n\n-----EXPANDED MOVE-----\n")
                 output_file.write(str(final_move_object))
예제 #6
0
 def create_expanded_ability(cls, pokemon_name__: str):
     """
     When expanded mode is applied, it will call this method to expand the
     ability URL taken from Pokemon Object.
     :param pokemon_name__:
     :return: Ability
     """
     request = pokedex.setup_request_commandline()
     ability_url = Pokemon.create_pokemon_object(pokemon_name__)
     ability_url_list = ability_url[1]
     async_ability_expanded = \
         asyncio.run(
             RequestApi.expanded_process_multiple_pokemon_requests(
                 ability_url_list))
     ability_expanded_dump = json.dumps(async_ability_expanded)
     ability_expanded_query = json.loads(ability_expanded_dump)
     print("\n---------------"
           "EXPANDED ABILITY INCLUDED-----------------------------")
     for ability in ability_expanded_query:
         ability_name = ability["name"]
         ability_id = ability["id"]
         ability_gen = ability["generation"]["name"]
         ability_long_effect = ability["effect_entries"][0]["effect"]
         ability_short_effect = ability["effect_entries"][0]["short_effect"]
         ability_pokemon = "\n-".join(
             [item["pokemon"]["name"] for item in ability["pokemon"]])
         final_ability_object = Ability(ability_name, ability_id,
                                        ability_gen, ability_long_effect,
                                        ability_short_effect,
                                        ability_pokemon)
         if request[3] is None:
             print(final_ability_object)
         elif request[3] is not None:
             with open(request[3], mode="a") as output_file:
                 output_file.write("\n\n-----EXPANDED ABILITY-----\n")
                 output_file.write(str(final_ability_object))