The API allows to create objects to be used such as pokemon and moves. At the beginning of your scripts add the import to Move and Pokemon classes
In [1]:
from pokelife.move import Move
from pokelife.pokemon import Pokemon
from pokelife.nature import Nature
The two classess connect to the REST API at pokeapi.co to collect data. To create a new move you can either use its id or its name
In [2]:
move_1 = Move(1)
move_2 = Move('razor-wind')
The print functions are overridden to show all the collected attributes from the database
In [3]:
print(move_1)
In [4]:
print(move_2)
All the attributes can be accessed individually
In [5]:
move_1.type
Out[5]:
You can instatiate pokemons in the exact same way
In [6]:
pokemon = Pokemon(12)
In [7]:
print(pokemon)
At creation, nature, abilities and moves are choosen randomly. You can change those element by simply setting them to another value
In [8]:
print('nature: %s' % pokemon.nature)
print('ability: %s' % pokemon.ability)
print('\n'.join("move %d: %s" % (i, move.name) for i, move in enumerate(pokemon.moves)))
In [9]:
pokemon.ability = 'compound-eyes'
print(pokemon.ability)
Accepted abilities are only those present in the list of available ones
In [12]:
pokemon.ability = 'stench'
You can also set an ability using set_ability_by_index(index) function. This function set as active ability the ability from the available list at selected index
In [13]:
pokemon.set_ability_by_index(0)
To change the list of active moves, you need to provide a list of four moves id. Move id can be either move names or corresponding integer id. The class automatically change it to the corresponding Move object
In [14]:
move_pool = ['mimic', 13, 'supersonic', 'toxic']
In [15]:
pokemon.moves = move_pool
In [16]:
print('\n'.join("move %d: %s" % (i, move.name) for i, move in enumerate(pokemon.moves)))
You can also set a move at a specific indec using the function set_move_at_index(move_number, id_move)
In [17]:
pokemon.set_move_at_index(3, 'reflect')
In [18]:
print('\n'.join("move %d: %s" % (i, move.name) for i, move in enumerate(pokemon.moves)))
In [ ]: