Ejemplo n.º 1
0
def load_gym_section(settings):
    log.info("Setting Gym filters...")
    # Set the defaults for "True"
    # Override defaults using a new Filter to verify inputs
    default_filt = GymFilter(settings.pop('default', {}), {
        "to_team": {0, 1, 2, 3}, "from_team": {0, 1, 2, 3},
        "min_dist": 0.0, "max_dist": float('inf')
    }, 'default')
    default = default_filt.to_dict()
    # Create the settings for gyms
    gym = {
        "enabled": bool(parse_boolean(settings.pop('enabled', None)) or False),
        "ignore_neutral": bool(parse_boolean(settings.pop('ignore_neutral', None)) or False),
        "filters": create_multi_filter('Gym --> filters', GymFilter,
                                       settings.pop('filters', "False"), default)
    }

    reject_leftover_parameters(settings, 'Gym section of Filters file.')  # Check for leftovers

    for filt in gym['filters']:
        log.debug("Team(s) {} changes to Team(s) {} between {} and {}.".format(
            filt.from_team, filt.to_team, get_dist_as_str(filt.min_dist), get_dist_as_str(filt.max_dist)
        ))
    if gym['enabled'] is False:
        log.info("Gym notifications will NOT be sent. - Enabled is False  ")
    return gym
Ejemplo n.º 2
0
def load_raid_section(settings):
    log.info("Setting Raid filters...")
    # Set the defaults for "True"
    # Override defaults using a new Filter to verify inputs
    default_filt = RaidFilter(settings.pop('default', {}), {
        "min_dist": 0.0, "max_dist": float('inf'),
        "min_level": 0, "max_level": 5,
    }, 'default')
    default = default_filt.to_dict()
    # Create the settings for raids
    raid = {
        "enabled": bool(parse_boolean(settings.pop('enabled', None)) or False),
        "filters": create_multi_filter('Raid --> filters', RaidFilter,
                                       settings.pop('filters', "False"), default)
    }

    reject_leftover_parameters(settings, 'Raid section of Filters file.')  # Check for leftovers

    for filt in raid['filters']:
        log.debug("Raid Level(s) {} to {} between {} and {}.".format(
            filt.min_level, filt.max_level, get_dist_as_str(filt.min_dist), get_dist_as_str(filt.max_dist)
        ))
    if raid['enabled'] is False:
        log.info("Raid notifications will NOT be sent. - Enabled is False  ")
    return raid
Ejemplo n.º 3
0
def load_gym_section(settings):
    log.info("Setting Gym filters...")
    # Set the defaults for "True"
    # Override defaults using a new Filter to verify inputs
    default_filt = GymFilter(settings.pop('default', {}), {
        "to_team": {0, 1, 2, 3}, "from_team": {0, 1, 2, 3},
        "min_dist": 0.0, "max_dist": float('inf')
    }, 'default')
    default = default_filt.to_dict()
    # Create the settings for gyms
    gym = {
        "enabled": bool(parse_boolean(settings.pop('enabled', None)) or False),
        "ignore_neutral": bool(parse_boolean(settings.pop('ignore_neutral', None)) or False),
        "filters": create_multi_filter('Gym --> filters', GymFilter,
                                       settings.pop('filters', "False"), default)
    }

    reject_leftover_parameters(settings, 'Gym section of Filters file.')  # Check for leftovers

    for filt in gym['filters']:
        log.debug("Team(s) {} changes to Team(s) {} between {} and {}.".format(
            filt.from_team, filt.to_team, get_dist_as_str(filt.min_dist), get_dist_as_str(filt.max_dist)
        ))
    if gym['enabled'] is False:
        log.info("Gym notifications will NOT be sent. - Enabled is False  ")
    return gym
Ejemplo n.º 4
0
def load_pokestop_section(settings):
    log.info("Setting Pokestop filters...")
    # Set the defaults settings for "True"
    default_true = {"min_dist": 0.0, "max_dist": float('inf')}
    stop = {
        "enabled": bool(parse_boolean(require_and_remove_key('enabled', settings, 'Pokestops')) or False),
        "filters": create_multi_filter('Pokestops --> filters', PokestopFilter,
                                       settings.pop('filters', "False"), default_true)
    }

    reject_leftover_parameters(settings, "Pokestops section of Filters file.")
    for filt in stop['filters']:
        log.debug("Between {} and {} away.".format(
            get_dist_as_str(filt.min_dist), get_dist_as_str(filt.max_dist)))
    if stop['enabled'] is False:
        log.info("Pokestop notifications will NOT be sent - Enabled is False.")
    return stop
Ejemplo n.º 5
0
def load_pokestop_section(settings):
    log.info("Setting Pokestop filters...")
    # Set the defaults settings for "True"
    default_true = {"min_dist": 0.0, "max_dist": float('inf')}
    stop = {
        "enabled": bool(parse_boolean(require_and_remove_key('enabled', settings, 'Pokestops')) or False),
        "filters": create_multi_filter('Pokestops --> filters', PokestopFilter,
                                       settings.pop('filters', "False"), default_true)
    }

    reject_leftover_parameters(settings, "Pokestops section of Filters file.")
    for filt in stop['filters']:
        log.debug("Between {} and {} away.".format(
            get_dist_as_str(filt.min_dist), get_dist_as_str(filt.max_dist)))
    if stop['enabled'] is False:
        log.info("Pokestop notifications will NOT be sent - Enabled is False.")
    return stop
Ejemplo n.º 6
0
    def process_gym_details(self, gym_details):
        if self.__gym_settings['enabled'] is False:
            log.debug("Gym ignored: notifications are disabled.")
            return

        # Extract some basic information
        gym_id = gym_details['id']
        to_team_id = gym_details['team_id']
        from_team_id = self.__gym_hist.get(gym_id)

        # Doesn't look like anything to me
        if to_team_id == from_team_id:
            log.debug("Gym ignored: no change detected")
            return
        # Ignore changes to neutral
        if self.__gym_settings['ignore_neutral'] and to_team_id == 0:
            log.debug("Gym update ignored: changed to neutral")
            return
        # Update gym's last known team
        self.__gym_hist[gym_id] = to_team_id
        # Ignore first time updates
        if from_team_id is None:
            log.debug("Gym update ignored: first time seeing this gym")
            return

        # Get some more info out used to check filters
        lat, lng = gym_details['lat'], gym_details['lng']
        dist = get_earth_dist([lat, lng], self.__latlng)
        cur_team = self.__team_name[to_team_id]
        old_team = self.__team_name[from_team_id]

        filters = self.__gym_settings['filters']
        passed = False
        for filt_ct in range(len(filters)):
            filt = filters[filt_ct]
            # Check the distance from the set location
            if dist != 'unkn':
                if filt.check_dist(dist) is False:
                    if self.__quiet is False:
                        log.info(
                            "Gym rejected: distance ({:.2f}) was not in range"
                            + " {:.2f} to {:.2f} (F #{})".format(
                                dist, filt.min_dist, filt.max_dist, filt_ct))
                    continue
            else:
                log.debug(
                    "Pokestop dist was not checked because the manager has no location set."
                )

            # Check the old team
            if filt.check_from_team(from_team_id) is False:
                if self.__quiet is False:
                    log.info(
                        "Gym rejected: {} as old team is not correct (F #{})".
                        format(old_team, filt_ct))
                continue
            # Check the new team
            if filt.check_to_team(to_team_id) is False:
                if self.__quiet is False:
                    log.info(
                        "Gym rejected: {} as current team is not correct (F #{})"
                        .format(cur_team, filt_ct))
                continue

            # Nothing left to check, so it must have passed
            passed = True
            log.debug("Gym passed filter #{}".format(filt_ct))
            break

        if not passed:
            return

        # Check the geofences
        gym['geofence'] = self.check_geofences('Gym', lat, lng)
        if len(self.__geofences) > 0 and gym['geofence'] == 'unknown':
            log.info("Gym rejected: not inside geofence(s)")
            return

        # Check if in geofences
        if len(self.__geofences) > 0:
            inside = False
            for gf in self.__geofences:
                inside |= gf.contains(lat, lng)
            if inside is False:
                if self.__quiet is False:
                    log.info("Gym update ignored: located outside geofences.")
                return
        else:
            log.debug(
                "Gym inside geofences was not checked because no geofences were set."
            )

        gym_details.update({
            'name': gym_details['name'],
            "dist": get_dist_as_str(dist),
            'dir': get_cardinal_dir([lat, lng], self.__latlng),
            'new_team': cur_team,
            'old_team': old_team,
            'defenders': gym_details['defenders']
        })
        self.add_optional_travel_arguments(gym_details)

        if self.__quiet is False:
            log.info(
                "Gym ({}) notification has been triggered!".format(gym_id))

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

        for thread in threads:
            thread.join()
Ejemplo n.º 7
0
    def process_pokestop(self, stop):
        # Make sure that pokemon are enabled
        if self.__pokestop_settings['enabled'] is False:
            log.debug("Pokestop ignored: pokestop notifications are disabled.")
            return

        id_ = stop['id']

        # Check for previously processed
        if id_ in self.__pokestop_hist:
            log.debug(
                "Pokestop was skipped because it was previously processed.")
            return
        self.__pokestop_hist[id_] = stop['expire_time']

        # Check the time remaining
        seconds_left = (stop['expire_time'] -
                        datetime.utcnow()).total_seconds()
        if seconds_left < self.__time_limit:
            if self.__quiet is False:
                log.info(
                    "Pokestop ({}) ignored: only {} seconds remaining.".format(
                        id_, seconds_left))
            return

        # Extract some basic information
        lat, lng = stop['lat'], stop['lng']
        dist = get_earth_dist([lat, lng], self.__latlng)
        passed = False
        filters = self.__pokestop_settings['filters']
        for filt_ct in range(len(filters)):
            filt = filters[filt_ct]
            # Check the distance from the set location
            if dist != 'unkn':
                if filt.check_dist(dist) is False:
                    if self.__quiet is False:
                        log.info(
                            "Pokestop rejected: distance ({:.2f}) was not in range"
                            .format(dist) + " {:.2f} to {:.2f} (F #{})".format(
                                filt.min_dist, filt.max_dist, filt_ct))
                    continue
            else:
                log.debug(
                    "Pokestop dist was not checked because the manager has no location set."
                )

            # Nothing left to check, so it must have passed
            passed = True
            log.debug("Pokstop passed filter #{}".format(filt_ct))
            break

        if not passed:
            return

        # Check the geofences
        stop['geofence'] = self.check_geofences('Pokestop', lat, lng)
        if len(self.__geofences) > 0 and stop['geofence'] == 'unknown':
            log.info("Pokestop rejected: not within any specified geofence")
            return

        time_str = get_time_as_str(stop['expire_time'], self.__timezone)
        stop.update({
            "dist": get_dist_as_str(dist),
            'time_left': time_str[0],
            '12h_time': time_str[1],
            '24h_time': time_str[2],
            'dir': get_cardinal_dir([lat, lng], self.__latlng),
        })
        self.add_optional_travel_arguments(stop)

        if self.__quiet is False:
            log.info(
                "Pokestop ({}) notification has been triggered!".format(id_))

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

        for thread in threads:
            thread.join()
Ejemplo n.º 8
0
    def process_pokemon(self, pkmn):
        # Make sure that pokemon are enabled
        if self.__pokemon_settings['enabled'] is False:
            log.debug("Pokemon ignored: pokemon notifications are disabled.")
            return

        # Extract some base information
        id_ = pkmn['id']
        pkmn_id = pkmn['pkmn_id']
        name = self.__pokemon_name[pkmn_id]

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

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

        # Check that the filter is even set
        if pkmn_id not in self.__pokemon_settings['filters']:
            if self.__quiet is False:
                log.info("{} ignored: no filters are set".format(name))
            return

        # Extract some useful info that will be used in the filters
        passed = False
        lat, lng = pkmn['lat'], pkmn['lng']
        dist = get_earth_dist([lat, lng], self.__latlng)
        iv = pkmn['iv']
        def_ = pkmn['def']
        atk = pkmn['atk']
        sta = pkmn['sta']
        quick_id = pkmn['quick_id']
        charge_id = pkmn['charge_id']
        size = pkmn['size']
        gender = pkmn['gender']
        form = pkmn['form']

        filters = self.__pokemon_settings['filters'][pkmn_id]
        for filt_ct in range(len(filters)):
            filt = filters[filt_ct]

            # Check the distance from the set location
            if dist != 'unkn':
                if filt.check_dist(dist) is False:
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: distance ({:.2f}) was not in range {:.2f} to {:.2f} (F #{})"
                            .format(name, dist, filt.min_dist, filt.max_dist,
                                    filt_ct))
                    continue
            else:
                log.debug(
                    "Filter dist was not checked because the manager has no location set."
                )

            # Check the IV percent of the Pokemon
            if iv != '?':
                if not filt.check_iv(iv):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: IV percent ({:.2f}) not in range {:.2f} to {:.2f} - (F #{})"
                            .format(name, iv, filt.min_iv, filt.max_iv,
                                    filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: 'IV' information was missing (F #{})".
                        format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon IV percent was not checked because it was missing."
                )

            # Check the Attack IV of the Pokemon
            if atk != '?':
                if not filt.check_atk(atk):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Attack IV ({}) not in range {} to {} - (F #{})"
                            .format(name, atk, filt.min_atk, filt.max_atk,
                                    filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Attack IV information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'atk' was not checked because it was missing.")

            # Check the Defense IV of the Pokemon
            if def_ != '?':
                if not filt.check_def(def_):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Defense IV ({}) not in range {} to {} - (F #{})"
                            .format(name, def_, filt.min_atk, filt.max_atk,
                                    filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Defense IV information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'def' was not checked because it was missing.")

            # Check the Stamina IV of the Pokemon
            if sta != '?':
                if not filt.check_sta(sta):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Stamina IV ({}) not in range {} to {} - (F #{})."
                            .format(name, def_, filt.min_sta, filt.max_sta,
                                    filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Stamina IV information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'sta' was not checked because it was missing.")

            # Check the Quick Move of the Pokemon
            if quick_id != '?':
                if not filt.check_quick_move(quick_id):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Quick move was not correct - (F #{})"
                            .format(name, filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Quick move information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'quick_id' was not checked because it was missing."
                )

            # Check the Quick Move of the Pokemon
            if charge_id != '?':
                if not filt.check_charge_move(charge_id):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Charge move was not correct - (F #{})"
                            .format(name, filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Charge move information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'charge_id' was not checked because it was missing."
                )

            # Check for a correct move combo
            if quick_id != '?' and charge_id != '?':
                if not filt.check_moveset(quick_id, charge_id):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Moveset was not correct - (F #{})".
                            format(name, filt_ct))
                    continue
            else:  # This will probably never happen? but just to be safe...
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Moveset information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'moveset' was not checked because it was missing."
                )

            # Check for a valid size
            if size != 'unknown':
                if not filt.check_size(size):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Size ({}) was not correct - (F #{})".
                            format(name, size, filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Size information was missing - (F #{})".
                        format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'size' was not checked because it was missing.")

            # Check for a valid gender
            if gender != 'unknown':
                if not filt.check_gender(gender):
                    if self.__quiet is False:
                        log.info(
                            "{} rejected: Gender ({}) was not correct - (F #{})"
                            .format(name, gender, filt_ct))
                    continue
            else:
                if filt.ignore_missing is True:
                    log.info(
                        "{} rejected: Gender information was missing - (F #{})"
                        .format(name, filt_ct))
                    continue
                log.debug(
                    "Pokemon 'gender' was not checked because it was missing.")

            # Nothing left to check, so it must have passed
            passed = True
            log.debug("{} passed filter #{}".format(name, filt_ct))
            break

        # If we didn't pass any filters
        if not passed:
            return

        # Check all the geofences
        pkmn['geofence'] = self.check_geofences(name, lat, lng)
        if len(self.__geofences) > 0 and pkmn['geofence'] == 'unknown':
            log.info("{} rejected: not inside geofence(s)".format(name))
            return

        # Finally, add in all the extra crap we waited to calculate until now
        time_str = get_time_as_str(pkmn['disappear_time'], self.__timezone)
        # If it has a form it's an unown and append form onto name
        if form != "unset":
            name = name + " - " + form
        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 != '?' else '?',
            'iv': "{:.1f}".format(iv) if iv != '?' else '?',
            'iv_2': "{:.2f}".format(iv) if iv != '?' else '?',
            'quick_move': self.__move_name.get(quick_id, 'unknown'),
            'charge_move': self.__move_name.get(charge_id, 'unknown')
        })
        self.add_optional_travel_arguments(pkmn)

        if self.__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.º 9
0
    def handle_gym(self, gym):
        # Quick check for enabled
        if self.__gym_filter['enabled'] is False:
            log.debug("Gym ignored: notifications are disabled.")
            return
        log.debug("Gyms set to {}.".format(self.__gym_filter['enabled']))

        id_ = gym['id']
        team_id = gym['team_id']
        old_team = self.__gym_hist.get(id_)

        # Ignore gyms when there is no change
        if old_team == team_id:
            log.debug("Gym update ignored: team didn't change")
            return

        # Ignore changes to neutral
        if self.__gym_filter['ignore_neutral'] and team_id == 0:
            log.debug("Gym update ignored: changed to neutral")
            return

        self.__gym_hist[id_] = team_id

        # Ignore first time updates
        if old_team is None:
            log.debug("Gym update ignored: first time seeing gym")
            return

        if old_team not in self.__gym_filter and team_id not in self.__gym_filter:
            if config['QUIET'] is False:
                log.info("Gym update ignored: neither team is enabled")
            return

        lat, lng = gym['lat'], gym['lng']
        dist = get_earth_dist([lat, lng], self.__latlng)
        if dist != 'unkn':
            old_range, new_range = False, False
            old_f = self.__gym_filter.get(old_team)
            if old_f is not None:
                old_range = old_f['min_dist'] <= dist <= old_f['max_dist']
            new_f = self.__gym_filter.get(team_id)
            if new_f is not None:
                new_range = new_f['min_dist'] <= dist <= new_f['max_dist']
            if old_range is False and new_range is False:
                if config['QUIET'] is False:
                    log.info("Gym update ignored: both teams outside range")
                return
        else:
            log.debug(
                "Gym distance was not checked because no location was set.")

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

        # Optional Stuff
        self.optional_arguments(gym)
        if config['QUIET'] is False:
            log.info("Gym ({}) notification has been triggered!".format(id_))

        gym.update({
            "dist": get_dist_as_str(dist) if dist != 'unkn' else 'unkn',
            'new_team': self.__team_name[team_id],
            'old_team': self.__team_name[old_team],
            'dir': get_cardinal_dir([lat, lng], self.__latlng),
        })

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

        for thread in threads:
            thread.join()
Ejemplo n.º 10
0
    def handle_pokestop(self, stop):
        # Quick check for enabled
        if self.__pokestop_filter['enabled'] is False:
            log.debug("Pokestop ignored: notifications are disabled.")
            return

        id_ = stop['id']

        # Check for previously processed (and make sure previous lure hasn't expired)
        if id_ in self.__pokestop_hist and self.__pokestop_hist[
                id_] >= datetime.utcnow():
            if config['QUIET'] is False:
                log.debug(
                    "Pokestop ({}) ignored: because it was previously notified."
                    .format(id_))
            return

        self.__pokestop_hist[id_] = expire_time = stop['expire_time']

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

        filt = self.__pokestop_filter

        # Check the distance from the set location
        lat, lng = stop['lat'], stop['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(
                        "Pokestop ({}) ignored: distance was not in range {:.2f} to {:.2f}."
                        .format(id_, filt['min_dist'], filt['max_dist']))
                return
        else:
            log.debug(
                "Pokestop distance was not checked because no location was set."
            )

        # 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("Pokestop ignored: located outside geofences.")
                return
        else:
            log.debug(
                "Pokestop inside geofences was not checked because no geofences were set."
            )

        time_str = get_time_as_str(expire_time, self.__timezone)
        stop.update({
            "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),
        })

        # Optional Stuff
        self.optional_arguments(stop)
        if config['QUIET'] is False:
            log.info(
                "Pokestop ({}) notification has been triggered!".format(id_))

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

        for thread in threads:
            thread.join()
Ejemplo n.º 11
0
    def process_gym(self, gym):
        gym_id = gym['id']

        # Update Gym details (if they exist)
        if gym_id not in self.__gym_info or gym['name'] != 'unknown':
            self.__gym_info[gym_id] = {
                "name": gym['name'],
                "description": gym['description'],
                "url": gym['url']
            }
            
# DMS raid control reporting********************************************************************
            to_team_id = gym['new_team_id']
            # Update gym's last known team
            self.__gym_hist[gym_id] = to_team_id
# DMS raid control reporting *********************************************************************

        if self.__gym_settings['enabled'] is False:
            log.debug("Gym ignored: notifications are disabled.")
            return

        # Extract some basic information
        to_team_id = gym['new_team_id']
        from_team_id = self.__gym_hist.get(gym_id)

        # Doesn't look like anything to me
        if to_team_id == from_team_id:
            log.debug("Gym ignored: no change detected")
            return
        # Ignore changes to neutral
        if self.__gym_settings['ignore_neutral'] and to_team_id == 0:
            log.debug("Gym update ignored: changed to neutral")
            return
        # Update gym's last known team
        self.__gym_hist[gym_id] = to_team_id

        # Ignore first time updates
        if from_team_id is None:
            log.debug("Gym update ignored: first time seeing this gym")
            return

        # Get some more info out used to check filters
        lat, lng = gym['lat'], gym['lng']
        dist = get_earth_dist([lat, lng], self.__location)
        cur_team = self.__locale.get_team_name(to_team_id)
        old_team = self.__locale.get_team_name(from_team_id)

        filters = self.__gym_settings['filters']
        passed = False
        for filt_ct in range(len(filters)):
            filt = filters[filt_ct]
            # Check the distance from the set location
            if dist != 'unkn':
                if filt.check_dist(dist) is False:
                    if self.__quiet is False:
                        log.info("Gym rejected: distance ({:.2f}) was not in range" +
                                 " {:.2f} to {:.2f} (F #{})".format(dist, filt.min_dist, filt.max_dist, filt_ct))
                    continue
            else:
                log.debug("Gym dist was not checked because the manager has no location set.")

            # Check the old team
            if filt.check_from_team(from_team_id) is False:
                if self.__quiet is False:
                    log.info("Gym rejected: {} as old team is not correct (F #{})".format(old_team, filt_ct))
                continue
            # Check the new team
            if filt.check_to_team(to_team_id) is False:
                if self.__quiet is False:
                    log.info("Gym rejected: {} as current team is not correct (F #{})".format(cur_team, filt_ct))
                continue

            # Nothing left to check, so it must have passed
            passed = True
            log.debug("Gym passed filter #{}".format(filt_ct))
            break

        if not passed:
            return

        # Check the geofences
        gym['geofence'] = self.check_geofences('Gym', lat, lng)
        if len(self.__geofences) > 0 and gym['geofence'] == 'unknown':
            log.info("Gym rejected: not inside geofence(s)")
            return

        # Check if in geofences
        if len(self.__geofences) > 0:
            inside = False
            for gf in self.__geofences:
                inside |= gf.contains(lat, lng)
            if inside is False:
                if self.__quiet is False:
                    log.info("Gym update ignored: located outside geofences.")
                return
        else:
            log.debug("Gym inside geofences was not checked because no geofences were set.")

        gym_info = self.__gym_info.get(gym_id, {})

        gym.update({
            "gym_name": gym_info.get('name', 'unknown'),
            "gym_description": gym_info.get('description', 'unknown'),
            "gym_url": gym_info.get('url', 'https://raw.githubusercontent.com/RocketMap/PokeAlarm/master/icons/gym_0.png'),
            "dist": get_dist_as_str(dist),
            'dir': get_cardinal_dir([lat, lng], self.__location),
            'new_team': cur_team,
            'new_team_id': to_team_id,
            'old_team': old_team,
            'old_team_id': from_team_id,
            'new_team_leader': self.__locale.get_leader_name(to_team_id),
            'old_team_leader': self.__locale.get_leader_name(from_team_id)
        })
        if self.__loc_service:
            self.__loc_service.add_optional_arguments(self.__location, [lat, lng], gym)

        if self.__quiet is False:
            log.info("Gym ({}) notification has been triggered!".format(gym_id))

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

        for thread in threads:
            thread.join()
Ejemplo n.º 12
0
    def process_pokemon(self, pkmn):
        # Make sure that pokemon are enabled
        if self.__pokemon_settings['enabled'] is False:
            log.debug("Pokemon ignored: pokemon notifications are disabled.")
            return

        # Extract some base information
        id_ = pkmn['id']
        pkmn_id = pkmn['pkmn_id']
        name = self.__locale.get_pokemon_name(pkmn_id)

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

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

        # Check that the filter is even set
        if pkmn_id not in self.__pokemon_settings['filters']:
            if self.__quiet is False:
                log.info("{} ignored: no filters are set".format(name))
            return

        # Extract some useful info that will be used in the filters

        lat, lng = pkmn['lat'], pkmn['lng']
        dist = get_earth_dist([lat, lng], self.__location)
        form_id = pkmn.get('form_id', 0)
        if form_id == '?':
            form_id = 0

        pkmn['pkmn'] = name

        filters = self.__pokemon_settings['filters'][pkmn_id]
        passed = self.check_pokemon_filter(filters, pkmn, dist)
        # If we didn't pass any filters
        if not passed:
            return

        quick_id = pkmn['quick_id']
        charge_id = pkmn['charge_id']
        weather_id = pkmn['weather']

        # Check all the geofences
        pkmn['geofence'] = self.check_geofences(name, lat, lng)
        if len(self.__geofences) > 0 and pkmn['geofence'] == 'unknown':
            log.info("{} rejected: not inside geofence(s)".format(name))
            return

        # Finally, add in all the extra crap we waited to calculate until now
        time_str = get_time_as_str(pkmn['disappear_time'], self.__timezone)
        iv = pkmn['iv']

        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.__location),
            'iv_0':
            "{:.0f}".format(iv) if iv != '?' else '?',
            'iv':
            "{:.1f}".format(iv) if iv != '?' else '?',
            'iv_2':
            "{:.2f}".format(iv) if iv != '?' else '?',
            'quick_move':
            self.__locale.get_move_name(quick_id),
            'charge_move':
            self.__locale.get_move_name(charge_id),
            'form_id':
            (chr(64 + int(form_id))) if form_id and int(form_id) > 0 else '',
            'weather':
            self.__locale.get_weather_name(weather_id)
        })
        if self.__loc_service:
            self.__loc_service.add_optional_arguments(self.__location,
                                                      [lat, lng], pkmn)

        if self.__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.º 13
0
    def process_raid(self, raid):
        # Quick check for enabled
        if self.__raid_settings['enabled'] is False:
            log.debug("Raid ignored: notifications are disabled.")
            return

        gym_id = raid['id']

        pkmn_id = raid['pkmn_id']
        raid_end = raid['raid_end']

        # raid history will contain the end date and also the pokemon if it has hatched
        if gym_id in self.__raid_hist:
            old_raid_end = self.__raid_hist[gym_id]['raid_end']
            old_raid_pkmn = self.__raid_hist[gym_id].get('pkmn_id', 0)
            if old_raid_end == raid_end:
                if old_raid_pkmn == pkmn_id:  # raid with same end time exists and it has same pokemon id, skip it
                    if self.__quiet is False:
                        log.info("Raid {} ignored. Was previously processed.".
                                 format(gym_id))
                    return

        self.__raid_hist[gym_id] = dict(raid_end=raid_end, pkmn_id=pkmn_id)

        # don't alert about expired raids
        seconds_left = (raid_end - datetime.utcnow()).total_seconds()
        if seconds_left < self.__time_limit:
            if self.__quiet is False:
                log.info("Raid {} ignored. Only {} seconds left.".format(
                    gym_id, seconds_left))
            return

        lat, lng = raid['lat'], raid['lng']
        dist = get_earth_dist([lat, lng], self.__location)

        # Check if raid is in geofences
        raid['geofence'] = self.check_geofences('Raid', lat, lng)
        if len(self.__geofences) > 0 and raid['geofence'] == 'unknown':
            if self.__quiet is False:
                log.info("Raid {} ignored: located outside geofences.".format(
                    gym_id))
            return
        else:
            log.debug(
                "Raid inside geofence was not checked because no geofences were set."
            )

        quick_id = raid['quick_id']
        charge_id = raid['charge_id']

        #  check filters for pokemon
        name = self.__locale.get_pokemon_name(pkmn_id)

        if pkmn_id not in self.__raid_settings['filters']:
            if self.__quiet is False:
                log.info("Raid on {} ignored: no filters are set".format(name))
            return

        raid_pkmn = {
            'pkmn': name,
            'cp': raid['cp'],
            'iv': 100,
            'level': 20,
            'def': 15,
            'atk': 15,
            'sta': 15,
            'gender': 'unknown',
            'size': 'unknown',
            'form_id': '?',
            'quick_id': quick_id,
            'charge_id': charge_id
        }

        filters = self.__raid_settings['filters'][pkmn_id]
        passed = self.check_pokemon_filter(filters, raid_pkmn, dist)
        # If we didn't pass any filters
        if not passed:
            log.debug("Raid {} did not pass pokemon check".format(gym_id))
            return

        if self.__loc_service:
            self.__loc_service.add_optional_arguments(self.__location,
                                                      [lat, lng], raid)

        if self.__quiet is False:
            log.info(
                "Raid ({}) notification has been triggered!".format(gym_id))

        time_str = get_time_as_str(raid['raid_end'], self.__timezone)
        start_time_str = get_time_as_str(raid['raid_begin'], self.__timezone)

        gym_info = self.__gym_info.get(gym_id, {})

        raid.update({
            'pkmn':
            name,
            #"gym_name": self.__gym_info.get(gym_id, {}).get('name', 'unknown'),
            #"gym_description": self.__gym_info.get(gym_id, {}).get('description', 'unknown'),
            #"gym_url": self.__gym_info.get(gym_id, {}).get('url', 'https://raw.githubusercontent.com/kvangent/PokeAlarm/master/icons/gym_0.png'),
            'time_left':
            time_str[0],
            '12h_time':
            time_str[1],
            '24h_time':
            time_str[2],
            'begin_time_left':
            start_time_str[0],
            'begin_12h_time':
            start_time_str[1],
            'begin_24h_time':
            start_time_str[2],
            "dist":
            get_dist_as_str(dist),
            'quick_move':
            self.__locale.get_move_name(quick_id),
            'charge_move':
            self.__locale.get_move_name(charge_id),
            #'team': self.__team_name[raid['team_id']],
            'dir':
            get_cardinal_dir([lat, lng], self.__location),
            'form':
            self.__locale.get_form_name(pkmn_id, raid_pkmn['form_id'])
        })

        threads = []
        # Spawn notifications in threads so they can work in background
        for alarm in self.__alarms:
            threads.append(gevent.spawn(alarm.raid_alert, raid))

            gevent.sleep(0)  # explict context yield

        for thread in threads:
            thread.join()
Ejemplo n.º 14
0
    def process_egg(self, egg):
        # Quick check for enabled
        if self.__egg_settings['enabled'] is False:
            log.debug("Egg ignored: notifications are disabled.")
            return

        gym_id = egg['id']

        raid_end = egg['raid_end']

        # raid history will contains any raid processed
        if gym_id in self.__raid_hist:
            old_raid_end = self.__raid_hist[gym_id]['raid_end']
            if old_raid_end == raid_end:
                if self.__quiet is False:
                    log.info(
                        "Raid {} ignored. Was previously processed.".format(
                            gym_id))
                return

        self.__raid_hist[gym_id] = dict(raid_end=raid_end, pkmn_id=0)

        # don't alert about (nearly) hatched eggs
        seconds_left = (egg['raid_begin'] - datetime.utcnow()).total_seconds()
        if seconds_left < self.__time_limit:
            if self.__quiet is False:
                log.info("Egg {} ignored. Egg hatch in {} seconds".format(
                    gym_id, seconds_left))
            return

        lat, lng = egg['lat'], egg['lng']
        dist = get_earth_dist([lat, lng], self.__location)

        # Check if raid is in geofences
        egg['geofence'] = self.check_geofences('Raid', lat, lng)
        if len(self.__geofences) > 0 and egg['geofence'] == 'unknown':
            if self.__quiet is False:
                log.info("Egg {} ignored: located outside geofences.".format(
                    gym_id))
            return
        else:
            log.debug(
                "Egg inside geofence was not checked because no geofences were set."
            )

        # check if the level is in the filter range or if we are ignoring eggs
        passed = self.check_egg_filter(self.__egg_settings, egg)

        if not passed:
            log.debug("Egg {} did not pass filter check".format(gym_id))
            return

        if self.__loc_service:
            self.__loc_service.add_optional_arguments(self.__location,
                                                      [lat, lng], egg)

        if self.__quiet is False:
            log.info(
                "Egg ({}) notification has been triggered!".format(gym_id))

        time_str = get_time_as_str(egg['raid_end'], self.__timezone)
        start_time_str = get_time_as_str(egg['raid_begin'], self.__timezone)

        gym_info = self.__gym_info.get(gym_id, {})

        egg.update({
            #"gym_name": self.__gym_info.get(gym_id, {}).get('name', 'unknown'),
            #"gym_description": self.__gym_info.get(gym_id, {}).get('description', 'unknown'),
            #"gym_url": self.__gym_info.get(gym_id, {}).get('url', 'https://raw.githubusercontent.com/kvangent/PokeAlarm/master/icons/gym_0.png'),
            'time_left': time_str[0],
            '12h_time': time_str[1],
            '24h_time': time_str[2],
            'begin_time_left': start_time_str[0],
            'begin_12h_time': start_time_str[1],
            'begin_24h_time': start_time_str[2],
            "dist": get_dist_as_str(dist),
            'dir': get_cardinal_dir([lat, lng], self.__location),
            #'team': self.__team_name[egg['team_id']]
        })

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

        for thread in threads:
            thread.join()
Ejemplo n.º 15
0
    def process_raid(self, raid):
        # Quick check for enabled
        if self.__raid_settings['enabled'] is False:
            log.debug("Raid ignored: notifications are disabled.")
            return

        gym_id = raid['id']

        pkmn_id = raid['pkmn_id']
        raid_end = raid['raid_end']

# DMS gym control reporting *************************************************************************************

        gteam = self.__gym_hist.get(gym_id)
        log.info("DMS Raid gym control team number:{}".format(gteam))
        
        if gteam == 1:
            gteamname = "Mystic"
        elif gteam == 2:
            gteamname = 'Valor'
        elif gteam  == 3:
            gteamname = 'Instinct'
        else:
            gteamname = 'Unknown/None'            
        
        log.info("DMS Raid gym control team string:{}".format(gteamname))

        #to_team_id = gym['new_team_id']
        #cur_team = self.__team_name[to_team_id]
#        gteam = gym_inf['new_team']
#        log.info("Raid gym control team:{}".format(gteam))

# DMS *************************************************************************************

# begin DMS eliminate raids in Great America  *************************************************************************************

        gname = self.__gym_info.get(gym_id, {}).get('name', 'unknown')
        log.info("DMS raid gym name {}".format(gname))

        if gname=='Ornate Elevated Vase':
            if self.__quiet is False:
                log.info("DMS Raid on {} ignored: GA Ornate Elevated Vase".format(gname))
            return

        if gname=='The Demon':
            if self.__quiet is False:
                log.info("DMS Raid on {} ignored: GA The Demon".format(gname))
            return

        if gname=='Frog Leg Pinwheel':
            if self.__quiet is False:
                log.info("DMS Raid on {} ignored: GA Frog Leg Pinwheel".format(gname))
            return

        if gname=='On the Mic Karaoke':
            if self.__quiet is False:
                log.info("DMS Raid on {} ignored: GA On the Mic Karaoke".format(gname))
            return

        if gname=='Boomerang Bay Torches':
            if self.__quiet is False:
                log.info("DMS Raid on {} ignored: GA Boomerang Bay Torches".format(gname))
            return

        if gname=='Water Mushrooms':
            if self.__quiet is False:
                log.info("Raid on {} ignored: GA Water Mushrooms".format(gname))
            return

        if gname=='Castaway Creek':
            if self.__quiet is False:
                log.info("DMS Raid on {} ignored: GA Castaway Creek".format(gname))
            return
        
# end DMS changes *************************************************************************************

        # raid history will contain the end date and also the pokemon if it has hatched
        if gym_id in self.__raid_hist:
            old_raid_end = self.__raid_hist[gym_id]['raid_end']
            old_raid_pkmn = self.__raid_hist[gym_id].get('pkmn_id', 0)
            if old_raid_end == raid_end:
                if old_raid_pkmn == pkmn_id:  # raid with same end time exists and it has same pokemon id, skip it
                    if self.__quiet is False:
                        log.info("Raid {} ignored. Was previously processed.".format(gym_id))
                    return

        self.__raid_hist[gym_id] = dict(raid_end=raid_end, pkmn_id=pkmn_id)

        # don't alert about expired raids
        seconds_left = (raid_end - datetime.utcnow()).total_seconds()
        if seconds_left < self.__time_limit:
            if self.__quiet is False:
                log.info("Raid {} ignored. Only {} seconds left.".format(gym_id, seconds_left))
            return

        lat, lng = raid['lat'], raid['lng']
        dist = get_earth_dist([lat, lng], self.__location)

        # Check if raid is in geofences
        raid['geofence'] = self.check_geofences('Raid', lat, lng)
        if len(self.__geofences) > 0 and raid['geofence'] == 'unknown':
            if self.__quiet is False:
                log.info("Raid {} ignored: located outside geofences.".format(gym_id))
            return
        else:
            log.debug("Raid inside geofence was not checked because no geofences were set.")

        quick_id = raid['quick_id']
        charge_id = raid['charge_id']

        #  check filters for pokemon
        name = self.__locale.get_pokemon_name(pkmn_id)

        if pkmn_id not in self.__raid_settings['filters']:
            if self.__quiet is False:
                log.info("Raid on {} ignored: no filters are set".format(name))
            return

        raid_pkmn = {
            'pkmn': name,
            'cp': raid['cp'],
            'iv': 100,
            'level': 20,
            'def': 15,
            'atk': 15,
            'sta': 15,
            'gender': 'unknown',
            'size': 'unknown',
            'form_id': '?',
            'quick_id': quick_id,
            'charge_id': charge_id
        }

        filters = self.__raid_settings['filters'][pkmn_id]
        passed = self.check_pokemon_filter(filters, raid_pkmn, dist)
        # If we didn't pass any filters
        if not passed:
            log.debug("Raid {} did not pass pokemon check".format(gym_id))
            return

        if self.__loc_service:
            self.__loc_service.add_optional_arguments(self.__location, [lat, lng], raid)

        if self.__quiet is False:
            log.info("Raid ({}) notification has been triggered!".format(gym_id))

        time_str = get_time_as_str(raid['raid_end'], self.__timezone)
        start_time_str = get_time_as_str(raid['raid_begin'], self.__timezone)

        gym_info = self.__gym_info.get(gym_id, {})

        raid.update({
            'pkmn': name,
            "gym_name": gym_info.get('name', 'unknown'),
            "gym_description": gym_info.get('description', 'unknown'),
            "gym_url": gym_info.get('url', 'https://raw.githubusercontent.com/RocketMap/PokeAlarm/master/icons/gym_0.png'),
            'time_left': time_str[0],
            '12h_time': time_str[1],
            '24h_time': time_str[2],
            'begin_time_left': start_time_str[0],
            'begin_12h_time': start_time_str[1],
#DMS raid gym control reporting hack            '24h_time': time_str[2],            
            '24h_time': gteamname,
            "dist": get_dist_as_str(dist),
            'dir': get_cardinal_dir([lat, lng], self.__location),
            'quick_move': self.__locale.get_move_name(quick_id),
            'charge_move': self.__locale.get_move_name(charge_id),
            'form': self.__locale.get_form_name(pkmn_id, raid_pkmn['form_id'])
        })

        threads = []
        # Spawn notifications in threads so they can work in background
        for alarm in self.__alarms:
            threads.append(gevent.spawn(alarm.raid_alert, raid))

            gevent.sleep(0)  # explict context yield

        for thread in threads:
            thread.join()
Ejemplo n.º 16
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']
        # TODO: Move damage
        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."
            )

        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)
        })
        # 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.º 17
0
    def process_raid(self, raid):
        # Make sure that pokemon are enabled
        if self.__raid_settings['enabled'] is False:
            log.debug("Raid ignored: raid notifications are disabled.")
            return

        id_ = raid['id']

        # Check for previously processed
        if id_ in self.__raid_hist:
            log.debug("Raid was skipped because it was previously processed.")
            return

        # Ignore if the Pokemon ID is still missing (it is an egg).
        # Store the raid start time in this case.
        if raid['pkmn_id'] == '?':
            log.info("Raid ({}) ignored: No pokemon exists.".format(id_))
            return

        else:
            # Store the raid end time and continue processing
            self.__raid_hist[id_] = raid['raid_end']

        # Extract some useful info that will be used in the filters
        passed = False
        lat, lng = raid['lat'], raid['lng']
        dist = get_earth_dist([lat, lng], self.__latlng)
        level = raid['level']
        pkmn_id = raid['pkmn_id']
        name = self.__pokemon_name[pkmn_id]

        filters = self.__raid_settings['filters']
        for filt_ct in range(len(filters)):
            filt = filters[filt_ct]
            # Check the distance from the set location
            if dist != 'unkn':
                if filt.check_dist(dist) is False:
                    if self.__quiet is False:
                        log.info(
                            "Raid rejected: distance ({:.2f}) was not in range"
                            .format(dist) + " {:.2f} to {:.2f} (F #{})".format(
                                filt.min_dist, filt.max_dist, filt_ct))
                    continue
            else:
                log.debug(
                    "Raid dist was not checked because the manager has no location set."
                )

            if not filt.check_level(level):
                if self.__quiet is False:
                    log.info(
                        "Raid rejected: Level ({}) not in range {} to {} - (F #{})"
                        .format(level, filt.min_level, filt.max_level,
                                filt_ct))
                continue

            # Nothing left to check, so it must have passed
            passed = True
            log.debug("Raid passed filter #{}".format(filt_ct))
            break

        if not passed:
            return

        # Check the geofences
        raid['geofence'] = self.check_geofences('Raid', lat, lng)
        if len(self.__geofences) > 0 and raid['geofence'] == 'unknown':
            log.info("Raid rejected: not within any specified geofence")
            return

        time_str = get_time_as_str(raid['raid_end'], self.__timezone)
        raid.update({
            "dist": get_dist_as_str(dist),
            'pkmn': name,
            'time_left': time_str[0],
            '12h_time': time_str[1],
            '24h_time': time_str[2],
            'dir': get_cardinal_dir([lat, lng], self.__latlng),
        })
        self.add_optional_travel_arguments(raid)

        if self.__quiet is False:
            log.info("Raid ({}/{}) notification has been triggered!".format(
                id_, name))

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

        for thread in threads:
            thread.join()