PokeAPI / pokepy

A Python wrapper for PokéAPI
https://pokeapi.co
BSD 3-Clause "New" or "Revised" License
127 stars 27 forks source link

Flavor text wrong language? #71

Closed ojmaster closed 3 years ago

ojmaster commented 3 years ago

So I’m trying to get the flavor text for a user inputted pokemon and I’ve got it working but I have 2 questions, some Pokémon’s flavor text are coming out in Japanese while others in English, I’ve noticed that everything past gen 5 isn’t in English, how do I set it to only display English and how do I choose what version.

Kronopt commented 3 years ago

Hi, The problem is most likely related with PokeAPI itself and not pokepy. If that's the case, please do report the issue on the PokeAPI repo.

In any case, can you give an example of what you're getting and how?

Kronopt commented 3 years ago

Still, most flavour text entries are a list of FlavorText, so you should be able to iterate over the list and select the language you want. That is, of course, if PokeAPI has the language you want available

ojmaster commented 3 years ago

Yeah really I just need an example for how I can make sure I'm getting the first available flavor text that's in English.

That is, of course, if PokeAPI has the language you want available

Kronopt commented 3 years ago

example:

import pokepy

client = pokepy.V2Client()
bulbasaur = client.get_pokemon_species(1)
for flavor in bulbasaur.flavor_text_entries:
    if flavor.language.name == 'en':
        print(flavor.flavor_text)
A strange seed was
planted on its
back at birth.The plant sprouts
and grows with
this POKéMON.
ojmaster commented 3 years ago

Thank you so much i feel like I should've known this but it's good to get help

ojmaster commented 3 years ago

@Kronopt so I'm able to get the Pokémon's generation but then when I try to find the game version I get an error

Your code earlier worked great but its not returning the first possible games flavor text (ex. Bulbasaur return red's, arceus will return diamond's) but whenever I try to get the version it returns an error

ojmaster commented 3 years ago
    pykemon = pokepy.V2Client()
    pk = pykemon.get_pokemon_species(pokemon)
    print(pk.generation.version_groups[1].name)

This is my code for getting the version group name but its returning that version_groups isnt a an attribute, yet yesterday when i was trying this it was workign fine, but now it isnt

ojmaster commented 3 years ago

i also just tried to get the version from the flavor text and its returning that flavortextsubersource object ahas no attribute version

Naramsim commented 3 years ago

Indeed the version is not accessible.

import pokepy
from pprint import pprint

pykemon = pokepy.V2Client()

pk = pykemon.get_pokemon_species('bulbasaur')

for text in pk.flavor_text_entries:
    pprint(vars(text))
    print(text.version.name)

You can try this code @Kronopt. Is there another way to get the version?

Naramsim commented 3 years ago

Ok, the FlavorTextSubResource didn't have the version sub-property. I added it in the master branch. Now we need to publish.

This code should be working with the new version

import pokepy
from pprint import pprint

pykemon = pokepy.V2Client()

pk = pykemon.get_pokemon_species('bulbasaur')

for text in pk.flavor_text_entries:
    if text.language.name == 'en':
        print('- Version {0}: {1}'.format(text.version.name, text.flavor_text))
Naramsim commented 3 years ago

I've published 0.6.2

https://pypi.org/project/pokepy/0.6.2/

Can you try it? @ojmaster

Kronopt commented 3 years ago

I guess I forgot to add the version property to the FlavorTextSubResource... that is my bad! Good catch @Naramsim!

ojmaster commented 3 years ago

It works now thank you @Naramsim

ojmaster commented 3 years ago

How would I get the games a Pokémon is introduced in. Also I think version_groups doesn't have subattribute version either

ojmaster commented 3 years ago

I can just make a check using the Pokémon's ID but I was wondering if you could determine the game versions directly from the Pokémon's name, my goal is to get the game the pokemon was introduced in and get the flavor text for that pokemon from that game

ojmaster commented 3 years ago

I have already gotten a way to find the games a certain Pokémon was introduced in just was wondering if there was a way to do get_pokemon_species(pokemon).version_groups[0].version.name Because it seems faster

ojmaster commented 3 years ago

I have already gotten a way to find the games a certain Pokémon was introduced in just was wondering if there was a way to do get_pokemon_species(pokemon).version_groups[0].version.name Because it seems faster

For this it says version is not an available subresource

Naramsim commented 3 years ago

To find out when a pokemon was released you can use the pokemon-species endpoint and then look at the generation property.

https://pokeapi.co/api/v2/pokemon-species/spectrier

ojmaster commented 3 years ago

Thank you 👍