API call pulls wrong id's for Gen 9 Pokemon
jack-skinner-552 opened this issue · 1 comments
jack-skinner-552 commented
The GET API call for "https://pokeapi.co/api/v2/" for a lot of Pokemon from Generation 9 are pulling incorrect id's.
See attached files. pokemon_correct.csv displays the correct id and name information, and pokemon_incorrect.csv was created from the following code:
import requests
import csv
# Set up the base URL for the PokeAPI
base_url = "https://pokeapi.co/api/v2/"
# Define the range of Pokemon IDs to list
start_id = 906
end_id = 1010
# Create a list to hold the Pokemon data
pokemon_data_list = []
# Loop through the range of IDs and make a request to the PokeAPI for each Pokemon
for pokemon_id in range(start_id, end_id+1):
# Construct the URL for the Pokemon with this ID
url = base_url + f"pokemon/{pokemon_id}/"
# Make a request to the PokeAPI for information about the Pokemon
response = requests.get(url)
# If the response was successful (i.e. the status code is 200), add the Pokemon's data to the list
if response.status_code == 200:
pokemon_data = response.json()
pokemon_name = pokemon_data["name"]
pokemon_data_list.append([pokemon_id, pokemon_name])
# Write the Pokemon data to a .csv file
with open("pokemon.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["ID", "Name"])
writer.writerows(pokemon_data_list)
print("Saved Pokemon data to pokemon_incorrect.csv")
Naramsim commented
Closing in favor of PokeAPI/pokeapi#863 (comment)