api_wrapper.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:PokemonGo-Bot 作者: PokemonGoF 项目源码 文件源码
def login(self, provider, username, password):
        # login needs base class "create_request"
        self.useVanillaRequest = True

        # Get Timecode and Country Code
        country_code = "US"
        timezone = "America/Chicago"
        geolocator = GoogleV3(api_key=self.config.gmapkey)

        if self.config.locale_by_location:
            try:
                location = geolocator.reverse((self.actual_lat, self.actual_lng), timeout = 10, exactly_one=True)
                country_code = self.get_component(location,'country')
            except:
                self.logger.warning("Please make sure you have google api key and enable Google Maps Geocoding API at console.developers.google.com")

            try:    
                timezone = geolocator.timezone([self.actual_lat, self.actual_lng], timeout=10)
            except:
                self.logger.warning("Please make sure you have google api key and enable Google Maps Time Zone API at console.developers.google.com")

        # Start login process
        try:
            if self.config.proxy:
                PGoApi.set_authentication(
                    self,
                    provider,
                    username=username,
                    password=password,
                    proxy_config={'http': self.config.proxy, 'https': self.config.proxy}
                )
            else:
                PGoApi.set_authentication(
                    self,
                    provider,
                    username=username,
                    password=password
                )
        except:
            raise
        try:
            if self.config.locale_by_location:
                response = PGoApi.app_simulation_login(self,country_code,timezone.zone)
            else:
                response = PGoApi.app_simulation_login(self) # To prevent user who have not update the api being caught off guard by errors
        except BadHashRequestException:
            self.logger.warning("Your hashkey seems to have expired or is not accepted!")
            self.logger.warning("Please set a valid hash key in your auth JSON file!")
            exit(-3)
            raise
        except BannedAccountException:
            self.logger.warning("This account is banned!")
            exit(-3)
            raise
        except:
            raise
        # cleanup code
        self.useVanillaRequest = False
        return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号