mirror of
https://github.com/LukeHagar/pokemonAPI-Amari.git
synced 2025-12-06 12:47:45 +00:00
29 lines
864 B
Python
Executable File
29 lines
864 B
Python
Executable File
# example_usage.py
|
|
|
|
from poke_sdk.PokeAPI import PokeAPI
|
|
|
|
def main():
|
|
# Create an instance of the PokeAPI class
|
|
api = PokeAPI()
|
|
|
|
# Fetch a Pokémon by name
|
|
try:
|
|
pikachu = api.get_pokemon("pikachu")
|
|
print(f"Retrieved Pokémon: {pikachu.name}")
|
|
print(f"ID: {pikachu.id}")
|
|
print(f"Types: {', '.join(pikachu.types)}")
|
|
except Exception as e:
|
|
print(f"An error occurred while fetching Pokémon: {e}")
|
|
|
|
# Fetch a generation by ID
|
|
try:
|
|
generation = api.get_generation("1")
|
|
print(f"Retrieved Generation: {generation.name}")
|
|
print(f"ID: {generation.id}")
|
|
print(f"Pokémon Species in this Generation: {', '.join(generation.pokemon_species)}")
|
|
except Exception as e:
|
|
print(f"An error occurred while fetching generation: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|