rubenvereecken / pokemongo-api

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

Add getting Gym detail, clean up #34

Closed Paramon closed 8 years ago

dnsBlah commented 8 years ago

Shouldn't you leave it out the way, and use only 1 function to retrieve forts. As a Pokestop is a Fort, and a Gym as well.

Just make the difference in findClosestPokestop, findClosestGym or just... findClosestFort if it doesnt matter where you go, and how extended the bot is ;-)

Paramon commented 8 years ago

If I understand correctly, we need sortCloseFort function like this:

def sortCloseFort(session, type = 1):
    logging.info("Sorting Nearest Forts:")
    cells = session.getMapObjects()
    latitude, longitude, _ = session.getCoordinates()
    forts = [fort for cell in cells.map_cells for fort in cell.forts if fort.type == type]
    return sorted(forts, key=lambda f: Location.getDistance(latitude, longitude, f.latitude, f.longitude))

And from findClosestGym call with type for Gym. If it's so I will do it. ;-)

Paramon commented 8 years ago

Yes. As a Pokemon select.

I suggest create something like "cell worker" class. Who extract all data from cells.

And move all logic of finding, filtering and sorting (rarity of Pokemons, Forts type, etc...) cell data in it.

dnsBlah commented 8 years ago

I believe there is no 'type' given in a Gym 'fort' I would remove the attribute in sortCloseForts

And do the loop and type check in

findClosestPokestop()
   forts = sortCloseForts
   for fort in forts:
       if fort.type and fort.type == 1:
           return fort

findClosestGym()
   forts = sortCloseForts
   for fort in forts:
#just to be sure, if there is type (not 100% sure about it atm)
       if not fort.type or fort.type != 1:
           return fort

Something like that :)

You can even set globals, pokestops {} gyms {} pokemons {}

and just return first occurance on them.