rubenvereecken / pokemongo-api

Pokemon Go API for Python
Other
358 stars 120 forks source link

Get ID's from names #40

Closed dnsBlah closed 8 years ago

dnsBlah commented 8 years ago

Hi all,

i would like to get the ID's using names (pokemon and items) That will make it a bit easier to put some config settings.

Like a argument, ignorepokemon ["pidgey","rattata"] etc.

But I'll need to get the ID from that string name.

Can we do that without making a new dictionary?

krzys-h commented 8 years ago

You can either use Pokedex and Items classes from this library:

from pokedex import Pokedex
from inventory import Items

print(getattr(Pokedex, 'PIDGEY'))
print(getattr(Pokedex, 'RATTATA'))
print(getattr(Items, 'POKE_BALL'))
print(getattr(Items, 'INCUBATOR_BASIC_UNLIMITED'))

Or you can use the protobufs directly:

import POGOProtos.Enums.PokemonId_pb2 as PokemonId_pb2
import POGOProtos.Inventory.ItemId_pb2 as ItemId_pb2

print(PokemonId_pb2.PokemonId.Value('PIDGEY'))
print(PokemonId_pb2.PokemonId.Value('RATTATA'))
print(ItemId_pb2.ItemId.Value('ITEM_POKE_BALL'))
print(ItemId_pb2.ItemId.Value('ITEM_INCUBATOR_BASIC_UNLIMITED'))

# You can also do that in reverse:
print(PokemonId_pb2.PokemonId.Name(16))
print(ItemId_pb2.ItemId.Name(1))
dnsBlah commented 8 years ago

I knew it was possible to do it reversed :) I'm not so very well known in Python, but doing good. Thanks!