示例#1
0
    def req_get_map_objects(self):
        """Scans current account location."""
        # Make sure that we don't hammer with GMO requests
        diff = self._last_gmo + self.cfg['scan_delay'] - time.time()
        if diff > 0:
            time.sleep(diff)

        # We jitter here because we need the jittered location NOW
        lat, lng = jitter_location(self.latitude, self.longitude)
        self._api.set_position(lat, lng, self.altitude)

        cell_ids = get_cell_ids(lat, lng)
        timestamps = [
            0,
        ] * len(cell_ids)
        responses = self.perform_request(
            lambda req: req.get_map_objects(latitude=f2i(lat),
                                            longitude=f2i(lng),
                                            since_timestamp_ms=timestamps,
                                            cell_id=cell_ids),
            get_inbox=True,
            jitter=False  # we already jittered
        )
        self._last_gmo = self._last_request

        return responses
示例#2
0
    def req_get_map_objects(self):
        """Scans current account location."""
        # Make sure that we don't hammer with GMO requests
        diff = self._last_gmo + self.cfg['scan_delay'] - time.time()
        if diff > 0:
            time.sleep(diff)

        # Jitter if wanted
        if self.cfg['jitter_gmo']:
            lat, lng = jitter_location(self.latitude, self.longitude)
        else:
            lat, lng = self.latitude, self.longitude

        cell_ids = get_cell_ids(lat, lng)
        timestamps = [
            0,
        ] * len(cell_ids)
        responses = self.perform_request(
            lambda req: req.get_map_objects(latitude=f2i(lat),
                                            longitude=f2i(lng),
                                            since_timestamp_ms=timestamps,
                                            cell_id=cell_ids),
            get_inbox=True)
        self._last_gmo = self._last_request

        return responses
示例#3
0
    def run(self):
        self.log_info("Waiting for job...")
        while True:
            if self.duplicate == 2:  # master account is banned so stop all duplicate accounts
                break
            (prio, t, job) = self.job_queue.get()
            try:
                if job.expired():
                    self.log_warning(
                        u"Scout job for {} at {}, {} expired. Rejecting.".
                        format(job.pokemon_name, job.lat, job.lng))
                    job.result = self.scout_error(self.last_msg, False)
                    continue

                self.log_info(
                    u"Scouting a {} at {}, {} with {} priority".format(
                        job.pokemon_name, job.lat, job.lng, PRIO_NAMES[prio]))

                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg, False)
                    if self.is_banned() or self.has_captcha():
                        break
                    else:
                        continue

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        time.sleep(2)
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error(
                            "Could not determine encounter_id for {} at {}, {}"
                            .format(job.pokemon_name, job.lat, job.lng), False)

                # Mark shadowbanned if too many errors
                sb_threshold = cfg_get('shadowban_threshold')
                if sb_threshold and self.errors >= sb_threshold:
                    self.shadowbanned = True

                if self.shadowbanned:
                    self.log_warning(
                        "Account probably shadowbanned. Stopping.")
                    break

            except (AuthException, BannedAccountException,
                    CaptchaException) as e:
                job.result = self.scout_error(self.last_msg, False)
                break
            except Exception:
                job.result = self.scout_error(repr(sys.exc_info()), False)
            finally:
                job.processed = True
                if self.is_banned() or self.has_captcha(
                ) or job.result["swap_account"]:
                    break
示例#4
0
    def _call_request(self, request, action=None, jitter=True):
        # Wait until a previous user action gets completed
        if action:
            now = time.time()
            # wait for the time required, or at least a half-second
            if self._last_action > now + .5:
                time.sleep(self._last_action - now)
            else:
                time.sleep(0.5)

        if jitter:
            lat, lng = jitter_location(self.latitude, self.longitude)
            self._api.set_position(lat, lng, self.altitude)

        success = False
        while not success:
            try:
                # Set hash key for this request
                old_hash_key = self._hash_key
                self._hash_key = self._hash_key_provider.next()
                if self._hash_key != old_hash_key:
                    self.log_debug("Using hash key {}".format(self._hash_key))
                self._api.activate_hash_server(self._hash_key)

                response = request.call()
                self._last_request = time.time()
                success = True
            except HashingQuotaExceededException as e:
                if self.cfg['retry_on_hash_quota_exceeded'] or self.cfg['retry_on_hashing_error']:
                    self.log_warning("{}: Retrying in 5s.".format(repr(e)))
                    time.sleep(5)
                else:
                    raise
            except (HashingOfflineException, HashingTimeoutException) as e:
                if self.cfg['retry_on_hashing_error']:
                    self.log_warning("{}: Retrying in 5s.".format(repr(e)))
                    time.sleep(5)
                else:
                    raise

        # status_code 3 means BAD_REQUEST, so probably banned
        if 'status_code' in response and response['status_code'] == 3:
            self.log_warning("Got BAD_REQUEST response.")
            raise BannedAccountException

        if not 'responses' in response:
            self.log_error("Got no responses at all!")
            return {}

        # Set the timer when the user action will be completed
        if action:
            self._last_action = self._last_request + action

        # Return only the responses
        responses = response['responses']

        self._parse_responses(responses)

        return responses
示例#5
0
    def run(self):
        self.log_info("Waiting for job...")
        while True:
            job = self.job_queue.get()
            try:
                self.log_info(u"Scouting a {} at {}, {}".format(
                    job.pokemon_name, job.lat, job.lng))
                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg)
                    if self.is_banned() or self.has_captcha():
                        break
                    else:
                        continue

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        time.sleep(2)
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error(
                            "Could not determine encounter_id for {} at {}, {}"
                            .format(job.pokemon_name, job.lat, job.lng))

                # Mark shadowbanned if too many errors
                sb_threshold = cfg_get('shadowban_threshold')
                if sb_threshold and self.errors >= sb_threshold:
                    self.shadowbanned = True

                if self.shadowbanned:
                    self.log_warning(
                        "Account probably shadowbanned. Stopping.")
                    break

            except (AuthException, BannedAccountException,
                    CaptchaException) as e:
                job.result = self.scout_error(self.last_msg)
                break
            except Exception:
                job.result = self.scout_error(repr(sys.exc_info()))
            finally:
                job.processed = True
                if self.is_banned() or self.has_captcha():
                    break
示例#6
0
文件: Scout.py 项目: pgandev/PGScout
    def run(self):
        self.log_info("Waiting for job...")
        while True:
            job = self.job_queue.get()
            try:
                self.log_info(u"Scouting a {} at {}, {}".format(
                    job.pokemon_name, job.lat, job.lng))
                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg)
                    continue

                # Check if banned.
                if self.is_banned():
                    job.result = self.scout_error("Account banned")
                    break

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        time.sleep(2)
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error(
                            "Could not determine encounter_id for {} at {}, {}"
                            .format(job.pokemon_name, job.lat, job.lng))

                # Check shadowban status
                if self.shadowbanned or self.errors >= cfg_get(
                        'shadowban_threshold'):
                    self.shadowbanned = True
                    self.log_warning(
                        "Account probably shadowbanned. Stopping.")
                    break

            except:
                job.result = self.scout_error(repr(sys.exc_info()))
            finally:
                job.processed = True
                self.update_history()
示例#7
0
    def run(self):
        self.log_info("Waiting for job...")
        while True:
            if self.shadowbanned:
                self.log_warning("Account shadowbanned. Stopping.")
                break

            job = self.job_queue.get()
            try:
                self.log_info(u"Scouting a {} at {}, {}".format(
                    job.pokemon_name, job.lat, job.lng))
                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg)
                    continue

                # Check if banned.
                if self.is_banned():
                    job.result = self.scout_error("Account banned")
                    break

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        time.sleep(2)
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error(
                            "Could not determine encounter_id for {} at {}, {}"
                            .format(job.pokemon_name, job.lat, job.lng))
            except:
                job.result = self.scout_error(repr(sys.exc_info()))
            finally:
                job.processed = True
                self.update_history()

        # We broke out of the main loop, so something is f*cked up with this scout.
        self.active = False
示例#8
0
    def run(self):
        self.log_info("Waiting for job...")
        while True:
            if self.shadowbanned:
                self.log_warning("Account shadowbanned. Stopping.")
                break

            job = self.job_queue.get()
            try:
                self.log_info(u"Scouting a {} at {}, {}".format(job.pokemon_name, job.lat, job.lng))
                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg)
                    continue

                # Check if banned.
                if self.is_banned():
                    job.result = self.scout_error("Account banned")
                    break

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error("Could not determine encounter_id for {} at {}, {}".format(job.pokemon_name, job.lat, job.lng))
            except :
                job.result = self.scout_error(repr(sys.exc_info()))
            finally:
                job.processed = True
                self.update_history()

        # We broke out of the main loop, so something is f*cked up with this scout.
        self.active = False
示例#9
0
文件: Scout.py 项目: pgandev/PGScout
 def jittered_location(self, job):
     (lat, lng) = jitter_location(job.lat, job.lng)
     self.set_position(lat, lng, job.altitude)
     return lat, lng
示例#10
0
    def _call_request(self, request, action=None, jitter=True):
        # Wait until a previous user action gets completed
        if action:
            now = time.time()
            # wait for the time required, or at least a half-second
            if self._last_action > now + .5:
                time.sleep(self._last_action - now)
            else:
                time.sleep(0.5)

        if jitter:
            lat, lng = jitter_location(self.latitude, self.longitude)
            self._api.set_position(lat, lng, self.altitude)

        success = False
        response = {}
        while not success:
            try:
                # Set hash key for this request
                if not self._hash_key_provider:
                    msg = "No hash key configured!"
                    self.log_error(msg)
                    raise NoHashKeyException()

                old_hash_key = self._hash_key
                self._hash_key = self._hash_key_provider.next()
                if self._hash_key != old_hash_key:
                    self.log_debug("Using hash key {}".format(self._hash_key))
                self._api.activate_hash_server(self._hash_key)

                response = request.call(use_dict=False)
                self._last_request = time.time()
                success = True
            except HashingQuotaExceededException as e:
                if self.cfg['retry_on_hash_quota_exceeded'] or self.cfg[
                        'retry_on_hashing_error']:
                    self.log_warning("{}: Retrying in 5s.".format(repr(e)))
                    time.sleep(5)
                else:
                    raise
            except (HashingOfflineException, HashingTimeoutException) as e:
                if self.cfg['retry_on_hashing_error']:
                    self.log_warning("{}: Retrying in 5s.".format(repr(e)))
                    time.sleep(5)
                else:
                    raise

        if not 'envelope' in response:
            self.log_warning('No response envelope. Something is wrong!')
            raise PgoapiError

        # status_code 3 means BAD_REQUEST, so probably banned
        status_code = response['envelope'].status_code
        if status_code == 3:
            self.log_warning("Got BAD_REQUEST response.")
            self._bad_request_ban = True
            raise BannedAccountException

        # Clean up
        del response['envelope']

        if not 'responses' in response:
            self.log_error("Got no responses at all!")
            return {}

        # Set the timer when the user action will be completed
        if action:
            self._last_action = self._last_request + action

        # Return only the responses
        responses = response['responses']

        self._parse_responses(responses)

        if self.needs_pgpool_update():
            self.update_pgpool()

        return responses
示例#11
0
 def jittered_location(self, job):
     (lat, lng) = jitter_location(job.lat, job.lng)
     self.set_position(lat, lng, job.altitude)
     return lat, lng
示例#12
0
    def _call_request(self, request, action=None, jitter=True):
        # Wait until a previous user action gets completed
        if action:
            now = time.time()
            # wait for the time required, or at least a half-second
            if self._last_action > now + .5:
                time.sleep(self._last_action - now)
            else:
                time.sleep(0.5)

        if jitter:
            lat, lng = jitter_location(self.latitude, self.longitude)
            self._api.set_position(lat, lng, self.altitude)

        req_method_list = copy.deepcopy(request._req_method_list)

        response = {}
        rotate_proxy = False
        while True:
            try:
                self.rotate_hash_key()
                if rotate_proxy:
                    self.rotate_proxy()
                    rotate_proxy = False

                response = request.call(use_dict=False)

                self._last_request = time.time()
                break
            except (ServerBusyOrOfflineException,
                    ServerSideRequestThrottlingException,
                    BadHashRequestException) as ex:
                # Retry unlimited - because it might be better to fail
                self.log_warning("{}: Retrying in 5s.".format(repr(ex)))
            except NianticIPBannedException as ex:
                # Rotate proxy
                self.log_warning("{}: Retrying in 5s.".format(repr(ex)))
                rotate_proxy = True
            except PgoapiError as ex:
                # This is bad.
                raise

            time.sleep(5)

        if not 'envelope' in response:
            self.log_warning('No response envelope. Something is wrong!')
            raise PgoapiError

        # status_code 3 means BAD_REQUEST, so probably banned
        status_code = response['envelope'].status_code
        if status_code == 3:
            log_suffix = ''
            if self.cfg['dump_bad_requests']:
                with open('BAD_REQUESTS.txt', 'a') as f:
                    f.write(repr(req_method_list))
                    f.close()
                log_suffix = ' Dumped request to BAD_REQUESTS.txt.'
            self.log_warning("Got BAD_REQUEST response.{}".format(log_suffix))
            self._bad_request_ban = True
            raise BannedAccountException

        # Clean up
        del response['envelope']

        if not 'responses' in response:
            self.log_error("Got no responses at all!")
            return {}

        # Set the timer when the user action will be completed
        if action:
            self._last_action = self._last_request + action

        # Return only the responses
        responses = response['responses']

        self._parse_responses(responses)

        if self.needs_pgpool_update():
            self.update_pgpool()

        return responses
示例#13
0
    def run(self):
        self.log_info("Waiting for job...")
        while True:
            job = self.job_queue.get()
            try:
                self.log_info(u"Scouting a {} at {}, {}".format(
                    job.pokemon_name, job.lat, job.lng))
                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg)
                    continue

                # Check if banned.
                if self.is_banned():
                    job.result = self.scout_error("Account banned")
                    break

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        time.sleep(2)
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error(
                            "Could not determine encounter_id for {} at {}, {}"
                            .format(job.pokemon_name, job.lat, job.lng))

                # Mark shadowbanned if too many errors
                sb_threshold = cfg_get('shadowban_threshold')
                if sb_threshold and self.errors >= sb_threshold:
                    self.shadowbanned = True

                if self.shadowbanned:
                    self.log_warning(
                        "Account probably shadowbanned. Stopping.")
                    break

            except:
                job.result = self.scout_error(repr(sys.exc_info()))
            finally:
                job.processed = True
                self.update_history()
                if job.result['message']['success']:
                    payload = {}
                    payload['pokehunt_id'] = job.result['message'][
                        'pokehunt_id']
                    #response = requests.post('http://192.168.1.101:1418/test4', json=payload)
                    cache_key = job.encounter_id if job.encounter_id else "{}-{}-{}".format(
                        pokemon_id, lat, lng)
                    cache_encounter(cache_key, job.result)
                    #return jsonify(job.result)
                    response = requests.post(cfg_get('customwebhook'),
                                             json=job.result)
                    if (response.status_code != 200):
                        log.error("Error sending webhook: {}".format(
                            response.raise_for_status()))
                    payload = {}
                    payload['pokehunt_id'] = job.result['message'][
                        'pokehunt_id']