PokeAPI / pokebase

Python 3 wrapper for Pokéapi v2
BSD 3-Clause "New" or "Revised" License
286 stars 53 forks source link

APIMetadata resource used for pokemon.sprites.other contains invalid key "official-artwork"; cannot get results #32

Closed mickelsendamon closed 2 years ago

mickelsendamon commented 2 years ago

The key for pokebase.pokemon(1).sprites.other.official-artwork is invalid syntax for Python and results in the "official-artwork" key to be unretrievable. Please update this to use _ instead of -.

I checked this for the first 99 Pokemon and got the same keys for each as in the example below: pokebase.pokemon(99).sprites.other = "{'dream_world': <pokebase.interface.APIMetadata object at 0x7f7f0752ce20>, 'official-artwork': <pokebase.interface.APIMetadata object at 0x7f7f0752cf10>}"

image

mickelsendamon commented 2 years ago

It looks like in the pokeapi data, the key is "official-artwork" and that just translates over to the APIMetadata object when it's parsing the data?

"sprites": {..., "other":{ "dream_world": ...}, "home":{...}, "official-artwork":{...} }, }, ...

mickelsendamon commented 2 years ago

The same thing is happening on .sprites.versions where the keys have "-" instead of "_" making the data inaccessible. Here's an example screenshot where the variable a = pokebase.pokemon(99). Let me know if I should open a separate Issue for this one.

image

C-Garza commented 2 years ago

It looks like from the readme that you have to use SpritesResource, although the readme is a bit wrong since a recent PR changed other_sprites to other, and I also don't think versions have been implemented yet. So something like this should get you the result you want for now:

>>> bulbasaur = pb.SpriteResource('pokemon', 1, other=True, official_artwork=True)
>>> print(bulbasaur.url)

'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/1.png'

I suppose I could make a PR to change those hyphens to underscores if that would help.

mickelsendamon commented 2 years ago

I see, thank you for pointing out the SpriteResource. I also see there is an APIResource, but the documentation is pretty bare when it comes to how to use them. For example, SpriteResource's first argument, 'sprite_type' leads me to think that either 'pokemon' or 'item' would be valid, but it doesn't appear that 'item' is a valid argument. Maybe the "Nomenclature" section of the Read Me can be updated to provide some more specific instructions for using the Resources?

However, there is a part of me that cringes at having an Object or dictionary with an invalid key, still.

C-Garza commented 2 years ago

Looks like the sprite_type is items and not item as shown here in common.py. The loaders.py file can show you the available functions to make up for the readme if that helps.

I've also opened up a PR for changing those hyphens to underscores so they can be chained.

mickelsendamon commented 2 years ago

Thanks a lot for your help. Looking forward to future improvements on this already great project!