Ejemplo n.º 1
0
    def pokemon(data):
        log.debug("Converting to pokemon: \n {}".format(data))
        # Get some stuff ahead of time (cause we are lazy)
        quick_id = check_for_none(int, data.get('move_1'), '?')
        charge_id = check_for_none(int, data.get('move_2'), '?')
        lat, lng = data['latitude'], data['longitude']
	weather_id = check_for_none(int, data.get('weather'), '?')

        # Generate all the non-manager specifi
        pkmn = {
            'type': "pokemon",
            'id': data['encounter_id'],
            'pkmn_id': int(data['pokemon_id']),
            'disappear_time': datetime.utcfromtimestamp(data['disappear_time']),
            'lat': float(data['latitude']),
            'lng': float(data['longitude']),
            'cp': check_for_none(int, data.get('cp'), '?'),
            'level': check_for_none(int, data.get('pokemon_level'), '?'),
            'iv': '?',
            'atk': check_for_none(int, data.get('individual_attack'), '?'),
            'def': check_for_none(int, data.get('individual_defense'), '?'),
            'sta': check_for_none(int, data.get('individual_stamina'), '?'),
            'quick_id': quick_id,
            'quick_damage': get_move_damage(quick_id),
            'quick_dps': get_move_dps(quick_id),
            'quick_duration': get_move_duration(quick_id),
            'quick_energy': get_move_energy(quick_id),
            'charge_id': charge_id,
            'charge_damage': get_move_damage(charge_id),
            'charge_dps': get_move_dps(charge_id),
            'charge_duration': get_move_duration(charge_id),
            'charge_energy': get_move_energy(charge_id),
            'height': check_for_none(float, data.get('height'), 'unkn'),
            'weight': check_for_none(float, data.get('weight'), 'unkn'),
            'gender': get_pokemon_gender(check_for_none(int, data.get('gender'), '?')),
            'form_id': check_for_none(int, data.get('form'), '?'),
            'size': 'unknown',
            'tiny_rat': '',
            'big_karp': '',
            'gmaps': get_gmaps_link(lat, lng),
            'applemaps': get_applemaps_link(lat, lng),
	    'weather': weather_id
        }
        if pkmn['atk'] != '?' or pkmn['def'] != '?' or pkmn['sta'] != '?':
            pkmn['iv'] = float(((pkmn['atk'] + pkmn['def'] + pkmn['sta']) * 100) / float(45))
        else:
            pkmn['atk'], pkmn['def'], pkmn['sta'] = '?', '?', '?'

        if pkmn['height'] != 'unkn' or pkmn['weight'] != 'unkn':
            pkmn['size'] = get_pokemon_size(pkmn['pkmn_id'], pkmn['height'], pkmn['weight'])
            pkmn['height'] = "{:.2f}".format(pkmn['height'])
            pkmn['weight'] = "{:.2f}".format(pkmn['weight'])

        if pkmn['pkmn_id'] == 19 and pkmn['size'] == 'tiny':
            pkmn['tiny_rat'] = 'tiny'

        if pkmn['pkmn_id'] == 129 and pkmn['size'] == 'big':
            pkmn['big_karp'] = 'big'

        return pkmn
Ejemplo n.º 2
0
    def pokemon(data):
        log.debug("Converting to pokemon: \n {}".format(data))
        # Get some stuff ahead of time (cause we are lazy)
        quick_id = check_for_none(int, data.get('move_1'), '?')
        charge_id = check_for_none(int, data.get('move_2'), '?')
        lat, lng = data['latitude'], data['longitude']
        # Generate all the non-manager specifi
        pkmn = {
            'type': "pokemon",
            'id': data['encounter_id'],
            'pkmn_id': int(data['pokemon_id']),
            'disappear_time': datetime.utcfromtimestamp(data['disappear_time']),
            'lat': float(data['latitude']),
            'lng': float(data['longitude']),
            'cp': check_for_none(int, data.get('cp'), '?'),
            'level': check_for_none(int, data.get('pokemon_level'), '?'),
            'iv': '?',
            'atk': check_for_none(int, data.get('individual_attack'), '?'),
            'def': check_for_none(int, data.get('individual_defense'), '?'),
            'sta': check_for_none(int, data.get('individual_stamina'), '?'),
            'quick_id': quick_id,
            'quick_damage': get_move_damage(quick_id),
            'quick_dps': get_move_dps(quick_id),
            'quick_duration': get_move_duration(quick_id),
            'quick_energy': get_move_energy(quick_id),
            'charge_id': charge_id,
            'charge_damage': get_move_damage(charge_id),
            'charge_dps': get_move_dps(charge_id),
            'charge_duration': get_move_duration(charge_id),
            'charge_energy': get_move_energy(charge_id),
            'height': check_for_none(float, data.get('height'), 'unkn'),
            'weight': check_for_none(float, data.get('weight'), 'unkn'),
            'gender': get_pokemon_gender(check_for_none(int, data.get('gender'), '?')),
            'form_id': check_for_none(int, data.get('form'), '?'),
            'size': 'unknown',
            'tiny_rat': '',
            'big_karp': '',
            'gmaps': get_gmaps_link(lat, lng),
            'applemaps': get_applemaps_link(lat, lng)
        }
        if pkmn['atk'] != '?' or pkmn['def'] != '?' or pkmn['sta'] != '?':
            pkmn['iv'] = float(((pkmn['atk'] + pkmn['def'] + pkmn['sta']) * 100) / float(45))
        else:
            pkmn['atk'], pkmn['def'], pkmn['sta'] = '?', '?', '?'

        if pkmn['height'] != 'unkn' or pkmn['weight'] != 'unkn':
            pkmn['size'] = get_pokemon_size(pkmn['pkmn_id'], pkmn['height'], pkmn['weight'])
            pkmn['height'] = "{:.2f}".format(pkmn['height'])
            pkmn['weight'] = "{:.2f}".format(pkmn['weight'])

        if pkmn['pkmn_id'] == 19 and pkmn['size'] == 'tiny':
            pkmn['tiny_rat'] = 'tiny'

        if pkmn['pkmn_id'] == 129 and pkmn['size'] == 'big':
            pkmn['big_karp'] = 'big'

        return pkmn
Ejemplo n.º 3
0
    def pokemon(data):
        log.debug("Converting to pokemon: \n {}".format(data))
        # Get some stuff ahead of time (cause we are lazy)
        quick_id = check_for_none(int, data.get('move_1'), '?')
        charge_id = check_for_none(int, data.get('move_2'), '?')
        lat, lng = data['latitude'], data['longitude']
        # Get the form from data and as it may be uint or string make sure is zero when string 'None'
        form_raw = data['form']
        if form_raw is None:
            form_raw = 0

        # Generate all the non-manager specifics
        pkmn = {
            'type':
            "pokemon",
            'id':
            data['encounter_id'],
            'pkmn_id':
            int(data['pokemon_id']),
            'disappear_time':
            datetime.utcfromtimestamp(data['disappear_time']),
            'lat':
            float(data['latitude']),
            'lng':
            float(data['longitude']),
            'iv':
            '?',
            'atk':
            check_for_none(int, data.get('individual_attack'), '?'),
            'def':
            check_for_none(int, data.get('individual_defense'), '?'),
            'sta':
            check_for_none(int, data.get('individual_stamina'), '?'),
            'quick_id':
            quick_id,
            'quick_damage':
            get_move_damage(quick_id),
            'quick_dps':
            get_move_dps(quick_id),
            'quick_duration':
            get_move_duration(quick_id),
            'quick_energy':
            get_move_energy(quick_id),
            'charge_id':
            charge_id,
            'charge_damage':
            get_move_damage(charge_id),
            'charge_dps':
            get_move_dps(charge_id),
            'charge_duration':
            get_move_duration(charge_id),
            'charge_energy':
            get_move_energy(charge_id),
            'height':
            check_for_none(float, data.get('height'), 'unkn'),
            'weight':
            check_for_none(float, data.get('weight'), 'unkn'),
            'gender':
            get_pokemon_gender(check_for_none(int, data.get('gender'), '?')),
            'size':
            'unknown',
            'previous_id':
            get_pkmn_name(int(data['previous_id'])),
            'gmaps':
            get_gmaps_link(lat, lng),
            'applemaps':
            get_applemaps_link(lat, lng),
            'form':
            get_form_name(int(form_raw))
        }
        if pkmn['atk'] != '?' or pkmn['def'] != '?' or pkmn['sta'] != '?':
            pkmn['iv'] = float(
                ((pkmn['atk'] + pkmn['def'] + pkmn['sta']) * 100) / float(45))
        else:
            pkmn['atk'], pkmn['def'], pkmn['sta'] = '?', '?', '?'

        if pkmn['height'] != 'unkn' or pkmn['weight'] != 'unkn':
            pkmn['size'] = get_pokemon_size(pkmn['pkmn_id'], pkmn['height'],
                                            pkmn['weight'])
            pkmn['height'] = "{:.2f}".format(pkmn['height'])
            pkmn['weight'] = "{:.2f}".format(pkmn['weight'])

        return pkmn
Ejemplo n.º 4
0
    def handle_pokemon(self, pkmn):
        # Quick check for enabled
        if self.__pokemon_filter['enabled'] is False:
            log.debug("Pokemon ignored: notifications are disabled.")
            return

        id_ = pkmn['id']
        pkmn_id = pkmn['pkmn_id']
        name = self.__pokemon_name[pkmn_id]

        # Check for previously processed
        if id_ in self.__pokemon_hist:
            if config['QUIET'] is False:
                log.debug(
                    "{} was skipped because it was previously processed.".
                    format(name))
            return
        self.__pokemon_hist[id_] = pkmn['disappear_time']

        # Check that the filter is set
        if pkmn_id not in self.__pokemon_filter:
            if config['QUIET'] is False:
                log.info("{} ignored: filter was not set".format(name))
            return

        # Check the time remaining
        seconds_left = (pkmn['disappear_time'] -
                        datetime.utcnow()).total_seconds()
        if seconds_left < self.__time_limit:
            if config['QUIET'] is False:
                log.info("{} ignored: {} seconds remaining.".format(
                    name, seconds_left))
            return

        filt = self.__pokemon_filter[pkmn_id]

        # Check the distance from the set location
        lat, lng = pkmn['lat'], pkmn['lng']
        dist = get_earth_dist([lat, lng], self.__latlng)
        if dist != 'unkn':
            if dist < filt['min_dist'] or filt['max_dist'] < dist:
                if config['QUIET'] is False:
                    log.info(
                        "{} ignored: distance ({:.2f}) was not in range {:.2f} to {:.2f}."
                        .format(name, dist, filt['min_dist'],
                                filt['max_dist']))
                return
        else:
            log.debug(
                "Pokemon dist was not checked because no location was set.")

        # Check the IV's of the Pokemon
        iv = pkmn['iv']
        if iv != 'unkn':
            if iv < filt['min_iv'] or filt['max_iv'] < iv:
                if config['QUIET'] is False:
                    log.info(
                        "{} ignored: IVs ({:.2f}) not in range {:.2f} to {:.2f}."
                        .format(name, iv, filt['min_iv'], filt['max_iv']))
                return
        else:
            log.debug(
                "Pokemon IV's were not checked because they are unknown.")
            if filt['ignore_missing'] is True:
                log.info("{} ignored: IV information was missing".format(name))
                return

        # Check the moves of the Pokemon
        move_1_id = pkmn['move_1_id']
        move_2_id = pkmn['move_2_id']
        if move_1_id != 'unknown' and move_2_id != 'unknown':
            move_1_f, move_2_f, moveset_f = filt['move_1'], filt[
                'move_2'], filt['moveset']
            if move_1_f is not None and move_1_id not in move_1_f:  # Check Move 1
                if config['QUIET'] is False:
                    log.info("{} ignored: Move 1 was incorrect.".format(name))
                return
            if move_2_f is not None and move_2_id not in move_2_f:  # Check Move 2
                if config['QUIET'] is False:
                    log.info("{} ignored: Move 2 was incorrect.".format(name))
                return
            if moveset_f is not None:  # Check for movesets
                correct_moves = False
                for filt in moveset_f:
                    correct_moves |= (move_1_id in filt and move_2_id in filt)
                if correct_moves is False:  # Wrong moveset
                    if config['QUIET'] is False:
                        log.info(
                            "{} ignored: Moveset was incorrect.".format(name))
                    return
        else:
            log.debug(
                "Pokemon moves were not checked because they are unknown.")
            if filt['ignore_missing'] is True:
                log.info(
                    "{} ignored: Moves information was missing".format(name))
                return

        # Check if in geofences
        if len(self.__geofences) > 0:
            inside = False
            for gf in self.__geofences:
                inside |= gf.contains(lat, lng)
            if not inside:
                if config['QUIET'] is False:
                    log.info(
                        "{} ignored: located outside geofences.".format(name))
                return
        else:
            log.debug(
                "Pokemon inside geofences was not checked because no geofences were set."
            )

        height, weight, gender = pkmn['height'], pkmn['weight'], pkmn['gender']
        if gender != '?':
            gender = u'\u2642' if gender is 1 else u'\u2640' if gender is 2 else u'\u26b2'  # male, female, neutral

        # Check the sizes of the Pokemon
        size = None
        if height != '?' and weight != '?':
            size = get_pokemon_size(pkmn_id, height, weight)
        if size is not None:
            size_f = filt['size']
            if size_f is not None and size not in size_f:
                if config['QUIET'] is False:
                    log.info("{} ignored: size was incorrect.".format(name))
                return
        else:
            log.debug(
                "Pokemon size were not checked because they are unknown.")
            if filt['ignore_missing'] is True:
                log.info(
                    "{} ignored: size information was missing".format(name))
                return

        time_str = get_time_as_str(pkmn['disappear_time'], self.__timezone)
        pkmn.update({
            'pkmn': name,
            "dist": get_dist_as_str(dist) if dist != 'unkn' else 'unkn',
            'time_left': time_str[0],
            '12h_time': time_str[1],
            '24h_time': time_str[2],
            'dir': get_cardinal_dir([lat, lng], self.__latlng),
            'iv_0': "{:.0f}".format(iv) if iv != 'unkn' else 'unkn',
            'iv': "{:.1f}".format(iv) if iv != 'unkn' else 'unkn',
            'iv_2': "{:.2f}".format(iv) if iv != 'unkn' else 'unkn',
            'move_1': self.__move_name.get(move_1_id, 'unknown'),
            'move_1_damage': get_move_damage(move_1_id),
            'move_1_dps': get_move_dps(move_1_id),
            'move_1_duration': get_move_duration(move_1_id),
            'move_1_energy': get_move_energy(move_1_id),
            'move_2': self.__move_name.get(move_2_id, 'unknown'),
            'move_2_damage': get_move_damage(move_2_id),
            'move_2_dps': get_move_dps(move_2_id),
            'move_2_duration': get_move_duration(move_2_id),
            'move_2_energy': get_move_energy(move_2_id),
            'height': "{:.1f}".format(height) if height != '?' else '?',
            'weight': "{:.1f}".format(weight) if weight != '?' else '?',
            'size': size if size is not None else 'unkn',
            'gender': gender
        })
        # Optional Stuff
        self.optional_arguments(pkmn)
        if config['QUIET'] is False:
            log.info("{} notification has been triggered!".format(name))

        threads = []
        # Spawn notifications in threads so they can work in background
        for alarm in self.__alarms:
            threads.append(gevent.spawn(alarm.pokemon_alert, pkmn))
            gevent.sleep(0)  # explict context yield

        for thread in threads:
            thread.join()
Ejemplo n.º 5
0
    def pokemon(data):
        #log.info("Converting to pokemon: \n {}".format(data))
        # Get some stuff ahead of time (cause we are lazy)
        quick_id = check_for_none(int, data.get('move_1'), '?')
        charge_id = check_for_none(int, data.get('move_2'), '?')
        lat, lng = data['latitude'], data['longitude']
        # Generate all the non-manager specifi
        pkmn = {
            'type':
            "pokemon",
            'id':
            data['encounter_id'],
            'pkmn_id':
            int(data['pokemon_id']),
            'disappear_time':
            datetime.utcfromtimestamp(data['disappear_time']),
            'lat':
            float(data['latitude']),
            'lng':
            float(data['longitude']),
            'cp':
            check_for_none(int, data.get('cp'), '?'),
            'level':
            check_for_none(int, data.get('pokemon_level'), '?'),
            'iv':
            '?',
            'atk':
            check_for_none(int, data.get('individual_attack'), '?'),
            'def':
            check_for_none(int, data.get('individual_defense'), '?'),
            'sta':
            check_for_none(int, data.get('individual_stamina'), '?'),
            'quick_id':
            quick_id,
            'quick_damage':
            get_move_damage(quick_id),
            'quick_dps':
            get_move_dps(quick_id),
            'quick_duration':
            get_move_duration(quick_id),
            'quick_energy':
            get_move_energy(quick_id),
            'charge_id':
            charge_id,
            'charge_damage':
            get_move_damage(charge_id),
            'charge_dps':
            get_move_dps(charge_id),
            'charge_duration':
            get_move_duration(charge_id),
            'charge_energy':
            get_move_energy(charge_id),
            'height':
            check_for_none(float, data.get('height'), '?'),
            'weight':
            check_for_none(float, data.get('weight'), '?'),
            'gender':
            get_pokemon_gender(check_for_none(int, data.get('gender'), '?')),
            'size':
            '?',
            'tiny_rat':
            '',
            'big_karp':
            '',
            'gmaps':
            get_gmaps_link(lat, lng),
            'applemaps':
            get_applemaps_link(lat, lng),
            'allstats':
            '',
            'rating_attack':
            data.get('rating_attack'),
            'rating_defense':
            data.get('rating_defense'),
            'worker_level':
            check_for_none(int, data.get('worker_level'), '?'),
            'catch_prob_1':
            check_for_none(float, data.get('catch_prob_1'), '?'),
            'catch_prob_2':
            check_for_none(float, data.get('catch_prob_2'), '?'),
            'catch_prob_3':
            check_for_none(float, data.get('catch_prob_3'), '?'),
            'previous_id':
            check_for_none(int, data.get('previous_id'), ''),
        }
        if pkmn['atk'] != '?' or pkmn['def'] != '?' or pkmn['sta'] != '?':
            pkmn['iv'] = float(
                ((pkmn['atk'] + pkmn['def'] + pkmn['sta']) * 100) / float(45))
        else:
            pkmn['atk'], pkmn['def'], pkmn['sta'] = '?', '?', '?'

        if pkmn['atk'] != '?' and pkmn['def'] != '?' and pkmn['sta'] != '?':
            pkmn['allstats'] = ' (%.0f' % (pkmn['iv']) + '%' + '/%d/%d/%d)' % (
                pkmn['atk'], pkmn['def'], pkmn['sta'])

            if pkmn['cp'] != '?':
                pkmn['allstats'] = pkmn['allstats'][:-1] + '/CP %d)' % (
                    pkmn['cp'])

            if pkmn['level'] != '?':
                pkmn['allstats'] = pkmn['allstats'][:-1] + '/Lvl %d)' % (
                    pkmn['level'])

        pkmn['allstats'] += ' '

        if pkmn['height'] != '?' or pkmn['weight'] != '?':
            pkmn['size'] = get_pokemon_size(pkmn['pkmn_id'], pkmn['height'],
                                            pkmn['weight'])
            pkmn['height'] = "{:.2f}".format(pkmn['height'])
            pkmn['weight'] = "{:.2f}".format(pkmn['weight'])

        if pkmn['pkmn_id'] == 19 and pkmn['size'] == 'tiny':
            pkmn['tiny_rat'] = 'Tiny'

        if pkmn['pkmn_id'] == 129 and pkmn['size'] == 'big':
            pkmn['big_karp'] = 'Big'

        rating_attack = pkmn['rating_attack']
        pkmn['rating_attack'] = rating_attack.upper() if rating_attack else '-'
        rating_defense = pkmn['rating_defense']
        pkmn['rating_defense'] = rating_defense.upper(
        ) if rating_defense else '-'

        if pkmn['catch_prob_1'] > 0:
            pkmn['catch_prob_1'] = pkmn['catch_prob_1'] * 100
            pkmn['catch_prob_1'] = int(round(pkmn['catch_prob_1'], 2))
        else:
            pkmn['catch_prob_1'] = ''

        if pkmn['catch_prob_2'] > 0:
            pkmn['catch_prob_2'] = pkmn['catch_prob_2'] * 100
            pkmn['catch_prob_2'] = int(round(pkmn['catch_prob_2'], 2))
        else:
            pkmn['catch_prob_2'] = ''

        if pkmn['catch_prob_3'] > 0:
            pkmn['catch_prob_3'] = pkmn['catch_prob_3'] * 100
            pkmn['catch_prob_3'] = int(round(pkmn['catch_prob_3'], 2))
        else:
            pkmn['catch_prob_3'] = ''

        if pkmn['previous_id']:
            pkmn['previous_id'] = '(' + get_pkmn_name(int(
                pkmn['previous_id'])) + ')'

        return pkmn
Ejemplo n.º 6
0
    def pokemon(data):
        log.debug("Converting to pokemon: \n {}".format(data))
        # Get some stuff ahead of time (cause we are lazy)
        quick_id = check_for_none(int, data.get('move_1'), '?')
        charge_id = check_for_none(int, data.get('move_2'), '?')
        lat, lng = data['latitude'], data['longitude']
        # Generate all the non-manager specifi
        pkmn = {
            'type':
            "pokemon",
            'id':
            data['encounter_id'],
            'pkmn_id':
            int(data['pokemon_id']),
            'disappear_time':
            datetime.utcfromtimestamp(data['disappear_time']),
            'lat':
            float(data['latitude']),
            'lng':
            float(data['longitude']),
            'iv':
            '?',
            'atk':
            check_for_none(int, data.get('individual_attack'), '?'),
            'def':
            check_for_none(int, data.get('individual_defense'), '?'),
            'sta':
            check_for_none(int, data.get('individual_stamina'), '?'),
            'quick_id':
            quick_id,
            'quick_damage':
            get_move_damage(quick_id),
            'quick_dps':
            get_move_dps(quick_id),
            'quick_duration':
            get_move_duration(quick_id),
            'quick_energy':
            get_move_energy(quick_id),
            'charge_id':
            charge_id,
            'charge_damage':
            get_move_damage(charge_id),
            'charge_dps':
            get_move_dps(charge_id),
            'charge_duration':
            get_move_duration(charge_id),
            'charge_energy':
            get_move_energy(charge_id),
            'height':
            check_for_none(float, data.get('height'), 'unkn'),
            'weight':
            check_for_none(float, data.get('weight'), 'unkn'),
            'gender':
            get_pokemon_gender(check_for_none(int, data.get('gender'), '?')),
            'size':
            'unknown',
            'gmaps':
            get_gmaps_link(lat, lng),
            'applemaps':
            get_applemaps_link(lat, lng),
            'cp':
            int(data['cp']),
            'cp_multiplier':
            str(data['cp_multiplier']),
            #'deeplink': config['DEEPLINK']+urllib.urlencode({'z': blowfishEncrypt(config['ENCRYPTION'], str(data['latitude'])[:11]+", "+str(data['longitude'])[:11])})
        }
        if pkmn['atk'] != '?' or pkmn['def'] != '?' or pkmn['sta'] != '?':
            pkmn['iv'] = float(
                ((pkmn['atk'] + pkmn['def'] + pkmn['sta']) * 100) / float(45))
        else:
            pkmn['atk'], pkmn['def'], pkmn['sta'] = '?', '?', '?'

        if pkmn['height'] != 'unkn' or pkmn['weight'] != 'unkn':
            pkmn['size'] = get_pokemon_size(pkmn['pkmn_id'], pkmn['height'],
                                            pkmn['weight'])
            pkmn['height'] = "{:.2f}".format(pkmn['height'])
            pkmn['weight'] = "{:.2f}".format(pkmn['weight'])

        return pkmn