Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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())
Ejemplo n.º 5
0
from pokesearch import Pokesearch
from pokeslack import Pokeslack
from pokeutil import get_pos_by_name

logger = logging.getLogger(__name__)

if __name__ == '__main__':

    logging.basicConfig(stream=sys.stdout, level=logging.INFO)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('pgoapi.pgoapi').setLevel(logging.WARNING)
    logging.getLogger('pgoapi.rpc_api').setLevel(logging.WARNING)

    logging.info('Pokeslack starting...')

    config = Pokeconfig()
    config.load_config('.env')

    auth_service = config.auth_service
    username = config.username
    password = config.password
    location_name = config.location_name
    rarity_limit = config.rarity_limit
    slack_webhook_url = config.slack_webhook_url
    num_steps = config.num_steps

    # debug vars, used to test slack integration w/o waiting
    use_cache = False
    cached_filename = 'cached_pokedata.json'
    search_timeout = 30