Closed mickelsendamon closed 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":{...} }, }, ...
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.
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.
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.
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.
Thanks a lot for your help. Looking forward to future improvements on this already great project!
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>}"