Пример #1
0
 def get_distance(self):
     position = Pokeconfig.get().position
     distance = vincenty(position, self.position)
     if Pokeconfig.get().distance_unit == 'meters':
         return distance.meters
     else:
         return distance.miles
Пример #2
0
    def try_send_pokemon(self, pokemon, debug):

        if pokemon.expires_in().total_seconds() < Pokeconfig.EXPIRE_BUFFER_SECONDS:
            logger.info('skipping pokemon since it expires too soon')
            return

        if pokemon.rarity < self.rarity_limit:
            logger.info('skipping pokemon since its rarity is too low')
            return

        padded_distance = pokemon.get_distance() * 1.1
        walk_distance_per_second = Pokeconfig.WALK_METERS_PER_SECOND if Pokeconfig.get().distance_unit == 'meters' else Pokeconfig.WALK_MILES_PER_SECOND
        travel_time = padded_distance / walk_distance_per_second
        if pokemon.expires_in().total_seconds() < travel_time:
            logger.info('skipping pokemon since it\'s too far: traveltime=%s for distance=%s', travel_time, pokemon.get_distance_str())
            return

        pokemon_key = pokemon.key
        if pokemon_key in self.sent_pokemon:
            logger.info('already sent this pokemon to slack with key %s', pokemon_key)
            return

        miles_away = pokemon.get_distance_str()

        position = Pokeconfig.get().position

        map_url = 'http://maps.google.com?saddr=%s,%s&daddr=%s,%s&directionsmode=walking' % (position[0], position[1], pokemon.position[0], pokemon.position[1])
        time_remaining = pokemon.expires_in_str()
        rarity = ''.join([':star:' for x in xrange(pokemon.rarity)])
        name = pokemon.name
        distance = miles_away
        disappear_time = time_remaining
        thumb_url = 'http://assets.pokemon.com/assets/cms2/img/pokedex/detail/'+str(pokemon.pokemon_id).zfill(3)+".png"
        travel_int = int(travel_time)
        if travel_int > 60 :
            m,s = divmod(travel_time,60)
            travel_time_str = "%dmin %02ds" % (m,s)
        else :
            travel_time_str = "%ds" %(travel_int)
        # bold message if rarity > 4
        # commented out, not sure if very necessary
        #if pokemon.rarity >= 4:
            #message = '*%s*' % message

        logging.info('%s: %s', pokemon_key, name)
        if self._send(name, distance, disappear_time, rarity, pokemon.from_lure, thumb_url, map_url, travel_time_str):
            self.sent_pokemon[pokemon_key] = True
Пример #3
0
    def try_send_pokemon(self, pokemon, debug):

        if pokemon.expires_in().total_seconds() < Pokeconfig.EXPIRE_BUFFER_SECONDS:
            logger.info('skipping pokemon since it expires too soon')
            return

        if pokemon.rarity < self.rarity_limit:
            logger.info('skipping pokemon since its rarity is too low')
            return

        padded_distance = pokemon.get_distance() * 1.1
        walk_distance_per_second = Pokeconfig.WALK_METERS_PER_SECOND if Pokeconfig.get().distance_unit == 'meters' else Pokeconfig.WALK_MILES_PER_SECOND
        travel_time = padded_distance / walk_distance_per_second
        if pokemon.expires_in().total_seconds() < travel_time:
            logger.info('skipping pokemon since it\'s too far: traveltime=%s for distance=%s', travel_time, pokemon.get_distance_str())
            return

        pokemon_key = pokemon.key
        if pokemon_key in self.sent_pokemon:
            logger.info('already sent this pokemon to slack with key %s', pokemon_key)
            return

        from_lure = ' (from a lure)' if pokemon.from_lure else ''
        miles_away = pokemon.get_distance_str()

        position = Pokeconfig.get().position

        pokedex_url = 'http://www.pokemon.com/us/pokedex/%s' % pokemon.pokemon_id
        map_url = 'http://maps.google.com?saddr=%s,%s&daddr=%s,%s&directionsmode=walking' % (position[0], position[1], pokemon.position[0], pokemon.position[1])
        time_remaining = pokemon.expires_in_str()
        #stars = ''.join([':star:' for x in xrange(pokemon.rarity)])
        pname = (pokemon.name).lower()
        message = 'Wild <%s|%s> appeared! It is <%s|%s away> and will disappear in %s%s.' % (pokedex_url, pokemon.name, map_url, miles_away, time_remaining, from_lure)
        # bold message if rarity > 4
        if pokemon.rarity >= 4:
            message = '*%s*' % message

        logging.info('%s: %s', pokemon_key, message)
        if self._send(message, pname):
            self.sent_pokemon[pokemon_key] = True
Пример #4
0
 def get_distance_str(self):
     if Pokeconfig.get().distance_unit == 'meters':
         return '{:.0f} m'.format(self.get_distance())    
     else:
         return '{:.3f} miles'.format(self.get_distance())