Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signatureconfig #4287

Merged
merged 5 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def check_session(self, position):
formatted='Session stale, re-logging in.'
)
position = self.position
self.api = ApiWrapper()
self.api = ApiWrapper(config=self.config)
self.position = position
self.login()
self.api.activate_signature(self.get_encryption_lib())
Expand Down Expand Up @@ -751,7 +751,7 @@ def get_encryption_lib(self):

def _setup_api(self):
# instantiate pgoapi
self.api = ApiWrapper()
self.api = ApiWrapper(config=self.config)

# provide player position on the earth
self._set_starting_position()
Expand Down
50 changes: 37 additions & 13 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import time
import logging
import random
import hashlib

from pgoapi.exceptions import (ServerSideRequestThrottlingException,
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException, EmptySubrequestChainException,
UnexpectedResponseException)
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException, EmptySubrequestChainException,
UnexpectedResponseException)
from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi
from pgoapi.protos.POGOProtos.Networking.Requests.RequestType_pb2 import RequestType
from pgoapi.protos.POGOProtos.Networking.Envelopes.Signature_pb2 import Signature
from pgoapi.utilities import get_time

from human_behaviour import sleep


class PermaBannedException(Exception):
pass


class ApiWrapper(PGoApi):
def __init__(self):
DEVICE_ID = None

def __init__(self, config=None):
PGoApi.__init__(self)
self.useVanillaRequest = False
self.config = config
if self.config is not None:
# Unique device id per account in the same format as ios client
ApiWrapper.DEVICE_ID = hashlib.md5(self.config.username).hexdigest()
if ApiWrapper.DEVICE_ID is None:
# Set to a realistic default
ApiWrapper.DEVICE_ID = "3d65919ca1c2fc3a8e2bd7cc3f974c34"

def create_request(self):
RequestClass = ApiRequest
Expand Down Expand Up @@ -67,7 +79,17 @@ def can_call(self):

def _call(self):
# Need fill in the location_fix
location_fix = Signature.LocationFix()
location_fix = [Signature.LocationFix(
provider='fused',
timestamp_snapshot=(get_time(ms=True) - RpcApi.START_TIME) - random.randint(100, 300),
latitude=self._position_lat,
longitude=self._position_lng,
horizontal_accuracy=round(random.uniform(50, 250), 7),
altitude=self._position_alt,
vertical_accuracy=random.randint(2, 5),
provider_status=3,
location_type=1
)]

sensor_info = Signature.SensorInfo(
timestamp_snapshot=(get_time(ms=True) - RpcApi.START_TIME) - random.randint(200, 400),
Expand All @@ -89,7 +111,7 @@ def _call(self):
accelerometer_axes=3
)
device_info = Signature.DeviceInfo(
device_id='HASHVALUE',
device_id=ApiWrapper.DEVICE_ID,
device_brand='Apple',
device_model='iPhone',
device_model_boot='iPhone8,2',
Expand All @@ -105,7 +127,7 @@ def _call(self):
# tilting=True
)
signature = Signature(
#location_fix=location_fix,
location_fix=location_fix,
sensor_info=sensor_info,
device_info=device_info,
activity_status=activity_status
Expand Down Expand Up @@ -146,7 +168,7 @@ def is_response_valid(self, result, request_callers):
def call(self, max_retry=15):
request_callers = self._pop_request_callers()
if not self.can_call():
return False # currently this is never ran, exceptions are raised before
return False # currently this is never ran, exceptions are raised before

request_timestamp = None
api_req_method_list = self._req_method_list
Expand All @@ -171,13 +193,14 @@ def call(self, max_retry=15):
throttling_retry += 1
if throttling_retry >= max_retry:
raise ServerSideRequestThrottlingException('Server throttled too many times')
sleep(1) # huge sleep ?
continue # skip response checking
sleep(1) # huge sleep ?
continue # skip response checking

if should_unexpected_response_retry:
unexpected_response_retry += 1
if unexpected_response_retry >= 5:
self.logger.warning('Server is not responding correctly to our requests. Waiting for 30 seconds to reconnect.')
self.logger.warning(
'Server is not responding correctly to our requests. Waiting for 30 seconds to reconnect.')
sleep(30)
else:
sleep(2)
Expand All @@ -186,7 +209,8 @@ def call(self, max_retry=15):
if not self.is_response_valid(result, request_callers):
try_cnt += 1
if try_cnt > 3:
self.logger.warning('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry))
self.logger.warning(
'Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry))
if try_cnt >= max_retry:
raise ServerBusyOrOfflineException()
sleep(1)
Expand All @@ -197,7 +221,7 @@ def call(self, max_retry=15):
return result

def __getattr__(self, func):
if func.upper() in RequestType.keys():
if func.upper() in RequestType.keys():
self.request_callers.append(func)
return PGoApiRequest.__getattr__(self, func)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy==1.11.0
networkx==1.11
-e git+https://github.com/joelgreen/pgoapi.git@1ee949e4299ddc8a5d8b9b41443640c2bf2fa5ca#egg=pgoapi
-e git+https://github.com/joelgreen/pgoapi.git/@b2927c5940a8d0febd41f006921d1c093542ddf8#egg=pgoapi
geopy==1.11.0
protobuf==3.0.0b4
requests==2.10.0
Expand Down