mirror of
https://github.com/LukeHagar/pokemonAPI-Amari.git
synced 2025-12-06 04:20:57 +00:00
Adding clean install to repo with project files
This commit is contained in:
28
example_usage_api.py
Normal file
28
example_usage_api.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# 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()
|
||||
Reference in New Issue
Block a user