def take_step(self): if self.config.evolve_all: # Run evolve all once. Flip the bit. print('[#] Attempting to evolve all pokemons ...') self.config.evolve_all = False self._evolve_all() position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) for step in range(self.steplimit2): # starting at 0 index logger.log('[#] Scanning area for objects ({} / {})'.format( (step + 1), self.steplimit**2)) if self.config.debug: logger.log( 'steplimit: {} x: {} y: {} pos: {} dx: {} dy {}'.format( self.steplimit2, self.x, self.y, self.pos, self.dx, self.dy)) # Scan location math if -self.steplimit2 / 2 < self.x <= self.steplimit2 / 2 and -self.steplimit2 / 2 < self.y <= self.steplimit2 / 2: position = (self.x * 0.0025 + self.origin_lat, self.y * 0.0025 + self.origin_lon, 0) if self.config.walk > 0: self._walk_to(self.config.walk, *position) else: self.api.set_position(*position) print('[#] {}'.format(position)) if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y: (self.dx, self.dy) = (-self.dy, self.dx) (self.x, self.y) = (self.x + self.dx, self.y + self.dy) self._work_at_position(position[0], position[1], position[2], True) sleep(10)
def _walk_to(self, speed, lat, lng, alt): dist = distance( i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng) steps = (dist + 0.0) / (speed + 0.0) # may be rational number intSteps = int(steps) residuum = steps - intSteps self.logger.info('[#] Walking from ' + str((i2f(self.api._position_lat), i2f( self.api._position_lng))) + " to " + str(str((lat, lng))) + " for approx. " + str(format_time(ceil(steps)))) if steps != 0: dLat = (lat - i2f(self.api._position_lat)) / steps dLng = (lng - i2f(self.api._position_lng)) / steps for i in range(intSteps): cLat = i2f(self.api._position_lat) + \ dLat + random_lat_long_delta() cLng = i2f(self.api._position_lng) + \ dLng + random_lat_long_delta() self.api.set_position(cLat, cLng, alt) self.bot.heartbeat() sleep(1) # sleep one second plus a random delta self._work_at_position( i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False) self.api.set_position(lat, lng, alt) self.bot.heartbeat() self.logger.info("[#] Finished walking")
def call(self, max_retry=25): request_callers = self._pop_request_callers() if not self._can_call(): return False # currently this is never ran, exceptions are raised before request_timestamp = None api_req_method_list = self._api._req_method_list result = None try_cnt = 0 while True: request_timestamp = self.throttle_sleep() self._api._req_method_list = [req_method for req_method in api_req_method_list] # api internally clear this field after a call result = self._api.call() if not self._is_response_valid(result, request_callers): try_cnt += 1 logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red') if try_cnt >= max_retry: raise ServerBusyOrOfflineException() sleep(1) else: break self.last_api_request_time = request_timestamp return result
def take_step(self): position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) for step in range(self.steplimit2): # starting at 0 index logger.log('[#] Scanning area for objects ({} / {})'.format( (step + 1), self.steplimit**2)) if self.config.debug: logger.log( 'steplimit: {} x: {} y: {} pos: {} dx: {} dy {}'.format( self.steplimit2, self.x, self.y, self.pos, self.dx, self.dy)) # Scan location math if -self.steplimit2 / 2 < self.x <= self.steplimit2 / 2 and -self.steplimit2 / 2 < self.y <= self.steplimit2 / 2: position = (self.x * 0.0025 + self.origin_lat, self.y * 0.0025 + self.origin_lon, 0) if self.config.walk > 0: self._walk_to(self.config.walk, *position) else: self.api.set_position(*position) print('[#] {}'.format(position)) if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y: (self.dx, self.dy) = (-self.dy, self.dx) (self.x, self.y) = (self.x + self.dx, self.y + self.dy) self._work_at_position(position[0], position[1], position[2], True) sleep(10)
def step(self): if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed: self.api.set_position(self.destLat, self.destLng, 0) self.bot.heartbeat() return True totalDLat = (self.destLat - self.initLat) totalDLng = (self.destLng - self.initLng) magnitude = self._pythagorean(totalDLat, totalDLng) unitLat = totalDLat / magnitude unitLng = totalDLng / magnitude scaledDLat = unitLat * self.magnitude scaledDLng = unitLng * self.magnitude cLat = self.initLat + scaledDLat + random_lat_long_delta() cLng = self.initLng + scaledDLng + random_lat_long_delta() self.api.set_position(cLat, cLng, 0) self.bot.event_manager.emit( 'position_update', sender=self, level='debug', data={ 'current_position': (cLat, cLng), 'last_position': (self.initLat, self.initLng), 'distance': '', 'distance_unit': '' } ) self.bot.heartbeat() sleep(1) # sleep one second plus a random delta
def _walk_to(self, speed, lat, lng, alt): dist = distance(i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng) steps = (dist + 0.0) / (speed + 0.0) # may be rational number intSteps = int(steps) residuum = steps - intSteps logger.log('[#] Walking from ' + str((i2f(self.api._position_lat), i2f(self.api._position_lng))) + " to " + str(str((lat, lng))) + " for approx. " + str(format_time(ceil(steps)))) if steps != 0: dLat = (lat - i2f(self.api._position_lat)) / steps dLng = (lng - i2f(self.api._position_lng)) / steps for i in range(intSteps): cLat = i2f(self.api._position_lat) + \ dLat + random_lat_long_delta() cLng = i2f(self.api._position_lng) + \ dLng + random_lat_long_delta() self.api.set_position(cLat, cLng, alt) self.bot.heartbeat() sleep(1) # sleep one second plus a random delta self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False) self.api.set_position(lat, lng, alt) self.bot.heartbeat() logger.log("[#] Finished walking")
def pokeball_inventory(self): sleep(1) self.api.get_player().get_inventory() inventory_req = self.api.call() inventory_dict = inventory_req['responses']['GET_INVENTORY'][ 'inventory_delta']['inventory_items'] user_web_inventory = 'web/inventory-%s.json' % (self.config.username) with open(user_web_inventory, 'w') as outfile: json.dump(inventory_dict, outfile) # get player balls stock # ---------------------- balls_stock = {1: 0, 2: 0, 3: 0, 4: 0} for item in inventory_dict: try: # print(item['inventory_item_data']['item']) item_id = item['inventory_item_data']['item']['item_id'] item_count = item['inventory_item_data']['item']['count'] if item_id == Item.ITEM_POKE_BALL.value: # print('Poke Ball count: ' + str(item_count)) balls_stock[1] = item_count if item_id == Item.ITEM_GREAT_BALL.value: # print('Great Ball count: ' + str(item_count)) balls_stock[2] = item_count if item_id == Item.ITEM_ULTRA_BALL.value: # print('Ultra Ball count: ' + str(item_count)) balls_stock[3] = item_count except: continue return balls_stock
def take_step(self): position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) for step in range(self.steplimit2): # starting at 0 index self.logger.info('[#] Scanning area for objects ({} / {})'.format( (step + 1), self.steplimit**2)) if self.config.debug: self.logger.info( 'steplimit: {} x: {} y: {} pos: {} dx: {} dy {}'.format( self.steplimit2, self.x, self.y, self.pos, self.dx, self.dy)) # Scan location math if -self.steplimit2 / 2 < self.x <= self.steplimit2 / 2 and -self.steplimit2 / 2 < self.y <= self.steplimit2 / 2: position = (self.x * 0.0025 + self.origin_lat, self.y * 0.0025 + self.origin_lon, 0) if self.config.walk > 0: self._walk_to(self.config.walk, *position) else: self.api.set_position(*position) print('[#] {}'.format(position)) if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y: (self.dx, self.dy) = (-self.dy, self.dx) (self.x, self.y) = (self.x + self.dx, self.y + self.dy) self._work_at_position(position[0], position[1], position[2], True) sleep(6)
def initial_transfer(self): logger.log('[x] Initial Transfer.') ignlist = self.config.ign_init_trans.split(',') if self.config.cp: logger.log('[x] Will NOT transfer anything above CP {} or these {}'.format( self.config.cp, ignlist)) else: logger.log('[x] Preparing to transfer all Pokemon duplicates, keeping the highest CP of each one type.') pokemon_groups = self._initial_transfer_get_groups() for id in pokemon_groups: group_cp = pokemon_groups[id].keys() if len(group_cp) > 1: group_cp.sort() group_cp.reverse() pokemon = self.pokemon_list[int(id - 1)] pokemon_name = pokemon['Name'] pokemon_num = pokemon['Number'].lstrip('0') for x in range(1, len(group_cp)): if (self.config.cp and group_cp[x] > self.config.cp) or (pokemon_name in ignlist or pokemon_num in ignlist): continue print('[x] Transferring #{} ({}) with CP {}'.format(id, pokemon_name, group_cp[x])) self.api.release_pokemon(pokemon_id=pokemon_groups[id][group_cp[x]]) response_dict = self.api.call() sleep(2) logger.log('[x] Transferring Done.')
def drop_item(self, item_id, count): sleep(1) self.api.recycle_inventory_item(item_id=item_id, count=count) inventory_req = self.api.call() # Example of good request response #{'responses': {'RECYCLE_INVENTORY_ITEM': {'result': 1, 'new_count': 46}}, 'status_code': 1, 'auth_ticket': {'expire_timestamp_ms': 1469306228058L, 'start': '/HycFyfrT4t2yB2Ij+yoi+on778aymMgxY6RQgvrGAfQlNzRuIjpcnDd5dAxmfoTqDQrbz1m2dGqAIhJ+eFapg==', 'end': 'f5NOZ95a843tgzprJo4W7Q=='}, 'request_id': 8145806132888207460L} return inventory_req
def _print_character_info(self): # get player profile call # ---------------------- self.api.get_player() response_dict = self.api.call() #print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2))) currency_1 = "0" currency_2 = "0" if response_dict: self._player = response_dict['responses']['GET_PLAYER']['player_data'] player = self._player else: logger.log("The API didn't return player info, servers are unstable - retrying.", 'red') sleep(5) self._print_character_info() # @@@ TODO: Convert this to d/m/Y H:M:S creation_date = datetime.datetime.fromtimestamp( player['creation_timestamp_ms'] / 1e3) creation_date = creation_date.strftime("%Y/%m/%d %H:%M:%S") pokecoins = '0' stardust = '0' items_stock = self.current_inventory() if 'amount' in player['currencies'][0]: pokecoins = player['currencies'][0]['amount'] if 'amount' in player['currencies'][1]: stardust = player['currencies'][1]['amount'] logger.log('') logger.log('--- {username} ---'.format(**player), 'cyan') self.get_player_info() logger.log('Pokemon Bag: {}/{}'.format(self.get_inventory_count('pokemon'), player['max_pokemon_storage']), 'cyan') logger.log('Items: {}/{}'.format(self.get_inventory_count('item'), player['max_item_storage']), 'cyan') logger.log('Stardust: {}'.format(stardust) + ' | Pokecoins: {}'.format(pokecoins), 'cyan') # Items Output logger.log('PokeBalls: ' + str(items_stock[1]) + ' | GreatBalls: ' + str(items_stock[2]) + ' | UltraBalls: ' + str(items_stock[3]), 'cyan') logger.log('RazzBerries: ' + str(items_stock[701]) + ' | BlukBerries: ' + str(items_stock[702]) + ' | NanabBerries: ' + str(items_stock[703]), 'cyan') logger.log('LuckyEgg: ' + str(items_stock[301]) + ' | Incubator: ' + str(items_stock[902]) + ' | TroyDisk: ' + str(items_stock[501]), 'cyan') logger.log('Potion: ' + str(items_stock[101]) + ' | SuperPotion: ' + str(items_stock[102]) + ' | HyperPotion: ' + str(items_stock[103]), 'cyan') logger.log('Incense: ' + str(items_stock[401]) + ' | IncenseSpicy: ' + str(items_stock[402]) + ' | IncenseCool: ' + str(items_stock[403]), 'cyan') logger.log('Revive: ' + str(items_stock[201]) + ' | MaxRevive: ' + str(items_stock[202]), 'cyan') logger.log('')
def take_step(self): position = (0, 0, 0) if self.first_step: self.first_step = False position = (self.origin_lat, self.origin_lon, 0.0) else: position = (i2f(self.api._position_lat), i2f(self.api._position_lng), 0.0) self.api.set_position(*position) self._work_at_position(position[0], position[1], position[2], True) sleep(5)
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 request_timestamp = None api_req_method_list = self._req_method_list result = None try_cnt = 0 throttling_retry = 0 unexpected_response_retry = 0 while True: request_timestamp = self.throttle_sleep() # self._call internally clear this field, so save it self._req_method_list = [ req_method for req_method in api_req_method_list ] should_throttle_retry = False should_unexpected_response_retry = False try: result = self._call() except ServerSideRequestThrottlingException: should_throttle_retry = True except UnexpectedResponseException: should_unexpected_response_retry = True if should_throttle_retry: throttling_retry += 1 if throttling_retry >= max_retry: raise ServerSideRequestThrottlingException( 'Server throttled too many times') 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.' ) sleep(30) else: sleep(2) continue 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)) if try_cnt >= max_retry: raise ServerBusyOrOfflineException() sleep(1) else: break self.last_api_request_time = request_timestamp return result
def step(self): if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed: self.api.set_position(self.destLat + random_lat_long_delta(), self.destLng + random_lat_long_delta(), 0) self.bot.event_manager.emit('position_update', sender=self, level='debug', data={ 'current_position': (self.destLat, self.destLng), 'last_position': (self.initLat, self.initLng), 'distance': '', 'distance_unit': '' }) self.bot.heartbeat() return True totalDLat = (self.destLat - self.initLat) totalDLng = (self.destLng - self.initLng) magnitude = self._pythagorean(totalDLat, totalDLng) unitLat = totalDLat / magnitude unitLng = totalDLng / magnitude scaledDLat = unitLat * self.magnitude scaledDLng = unitLng * self.magnitude cLat = self.initLat + scaledDLat + random_lat_long_delta() cLng = self.initLng + scaledDLng + random_lat_long_delta() self.api.set_position(cLat, cLng, 0) self.bot.event_manager.emit('position_update', sender=self, level='debug', data={ 'current_position': (cLat, cLng), 'last_position': (self.initLat, self.initLng), 'distance': '', 'distance_unit': '' }) self.bot.heartbeat() sleep(1) # sleep one second plus a random delta
def item_inventory_count(self, id): sleep(1) self.api.get_player().get_inventory() inventory_req = self.api.call() inventory_dict = inventory_req['responses'][ 'GET_INVENTORY']['inventory_delta']['inventory_items'] item_count = 0 for item in inventory_dict: try: if item['inventory_item_data']['item']['item_id'] == int(id): item_count = item[ 'inventory_item_data']['item']['count'] except: continue return item_count
def _walk_to(self, speed, lat, lng, alt): origin = ','.join([str(self.api._position_lat), str(self.api._position_lng)]) destination = ','.join([str(lat), str(lng)]) polyline_walker = PolylineWalker(origin, destination, self.speed) proposed_origin = polyline_walker.points[0] proposed_destination = polyline_walker.points[-1] proposed_lat = proposed_origin[0] proposed_lng = proposed_origin[1] if proposed_lat != lat and proposed_lng != lng: self._old_walk_to(speed, proposed_lat, proposed_lng, alt) while proposed_destination != polyline_walker.get_pos()[0]: cLat, cLng = polyline_walker.get_pos()[0] self.api.set_position(cLat, cLng, alt) self.bot.heartbeat() self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False) sleep(1) # sleep one second plus a random delta if proposed_lat != self.api._position_lat and proposed_lng != self.api._position_lng: self._old_walk_to(speed, lat, lng, alt)
def _walk_to(self, speed, lat, lng, alt): origin = ",".join([str(self.api._position_lat), str(self.api._position_lng)]) destination = ",".join([str(lat), str(lng)]) polyline_walker = PolylineWalker(origin, destination, self.speed) proposed_origin = polyline_walker.points[0] proposed_destination = polyline_walker.points[-1] proposed_lat = proposed_origin[0] proposed_lng = proposed_origin[1] if proposed_lat != lat and proposed_lng != lng: self._old_walk_to(speed, proposed_lat, proposed_lng, alt) while proposed_destination != polyline_walker.get_pos()[0]: cLat, cLng = polyline_walker.get_pos()[0] self.api.set_position(cLat, cLng, alt) self.bot.heartbeat() self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False) sleep(1) # sleep one second plus a random delta if proposed_lat != self.api._position_lat and proposed_lng != self.api._position_lng: self._old_walk_to(speed, lat, lng, alt)
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 request_timestamp = None api_req_method_list = self._req_method_list result = None try_cnt = 0 throttling_retry = 0 unexpected_response_retry = 0 while True: request_timestamp = self.throttle_sleep() # self._call internally clear this field, so save it self._req_method_list = [req_method for req_method in api_req_method_list] should_throttle_retry = False should_unexpected_response_retry = False try: result = self._call() except ServerSideRequestThrottlingException: should_throttle_retry = True except UnexpectedResponseException: should_unexpected_response_retry = True if should_throttle_retry: throttling_retry += 1 if throttling_retry >= max_retry: raise ServerSideRequestThrottlingException('Server throttled too many times') 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.') sleep(30) else: sleep(2) continue 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)) if try_cnt >= max_retry: raise ServerBusyOrOfflineException() sleep(1) else: break self.last_api_request_time = request_timestamp return result
def walk_to(self, speed, lat, lng, alt): dist = distance(i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng) steps = (dist / (self.AVERAGE_STRIDE_LENGTH_IN_METRES * speed)) logger.log("[#] Walking from " + str((i2f(self.api._position_lat), i2f(self.api._position_lng))) + " to " + str(str((lat, lng))) + " for approx. " + str(format_time(ceil(steps)))) if steps != 0: d_lat = (lat - i2f(self.api._position_lat)) / steps d_long = (lng - i2f(self.api._position_lng)) / steps for i in range(int(steps)): c_lat = i2f(self.api._position_lat) + d_lat + random_lat_long_delta() c_long = i2f(self.api._position_lng) + d_long + random_lat_long_delta() self.api.set_position(c_lat, c_long, alt) self.bot.heartbeat() sleep(1) # sleep one second plus a random delta self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False) self.api.set_position(lat, lng, alt) self.bot.heartbeat() logger.log("[#] Finished walking")
def step(self): if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed: self.api.set_position(self.destLat, self.destLng, 0) return True totalDLat = (self.destLat - self.initLat) totalDLng = (self.destLng - self.initLng) magnitude = self._pythagorean(totalDLat, totalDLng) unitLat = totalDLat / magnitude unitLng = totalDLng / magnitude scaledDLat = unitLat * self.magnitude scaledDLng = unitLng * self.magnitude cLat = self.initLat + scaledDLat + random_lat_long_delta() cLng = self.initLng + scaledDLng + random_lat_long_delta() self.api.set_position(cLat, cLng, 0) self.bot.heartbeat() sleep(1) # sleep one second plus a random delta
def update_inventory(self): sleep(1) self.api.get_inventory() response = self.api.call() self.inventory = list() if 'responses' in response: if 'GET_INVENTORY' in response['responses']: if 'inventory_delta' in response['responses']['GET_INVENTORY']: if 'inventory_items' in response['responses'][ 'GET_INVENTORY']['inventory_delta']: for item in response['responses']['GET_INVENTORY'][ 'inventory_delta']['inventory_items']: if not 'inventory_item_data' in item: continue if not 'item' in item['inventory_item_data']: continue if not 'item_id' in item['inventory_item_data'][ 'item']: continue if not 'count' in item['inventory_item_data'][ 'item']: continue self.inventory.append(item['inventory_item_data'][ 'item'])
def compute_release_under_cp(self): # update 'release_under_cp' with current max cp in inventory sleep(1) self.api.get_player().get_inventory() inventory_req = self.api.call() inventory_dict = inventory_req['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'] for pokemon in inventory_dict: try: reduce(dict.__getitem__, ["inventory_item_data", "pokemon_data", "pokemon_id"], pokemon) except KeyError: continue pokemon_num = int(pokemon['inventory_item_data']['pokemon_data']['pokemon_id']) - 1 pokemon_name = self.pokemon_list[int(pokemon_num)]['Name'] # logger.log('[#] pokemon_name: ' + pokemon_name) pokemon_cp = pokemon['inventory_item_data']['pokemon_data']['cp'] current_pokemon_release_config = self.config.release_config.get(pokemon_name) if current_pokemon_release_config.get('release_under_cp') < pokemon_cp: current_pokemon_release_config['release_under_cp'] = pokemon_cp self.config.release_config[pokemon_name] = current_pokemon_release_config ## Print all pokemon print_all_iv(pokemon, pokemon_name, pokemon_cp)
def _setup_api(self): # instantiate pgoapi self.api = PGoApi() # check if the release_config file exists try: with open('release_config.json') as file: pass except: # the file does not exist, warn the user and exit. logger.log('[#] IMPORTANT: Rename and configure release_config.json.example for your Pokemon release logic first!', 'red') exit(0) # provide player position on the earth self._set_starting_position() if not self.api.login(self.config.auth_service, str(self.config.username), str(self.config.password)): logger.log('Login Error, server busy', 'red') exit(0) # chain subrequests (methods) into one RPC call # get player profile call # ---------------------- self.api.get_player() sleep(1) response_dict = self.api.call() #print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2))) currency_1 = "0" currency_2 = "0" player = response_dict['responses']['GET_PLAYER']['player_data'] # @@@ TODO: Convert this to d/m/Y H:M:S creation_date = datetime.datetime.fromtimestamp( player['creation_timestamp_ms'] / 1e3) pokecoins = '0' stardust = '0' balls_stock = self.pokeball_inventory() if 'amount' in player['currencies'][0]: pokecoins = player['currencies'][0]['amount'] if 'amount' in player['currencies'][1]: stardust = player['currencies'][1]['amount'] logger.log('[#] Username: {username}'.format(**player)) logger.log('[#] Acccount Creation: {}'.format(creation_date)) logger.log('[#] Bag Storage: {}/{}'.format( self.get_inventory_count('item'), player['max_item_storage'])) logger.log('[#] Pokemon Storage: {}/{}'.format( self.get_inventory_count('pokemon'), player[ 'max_pokemon_storage'])) logger.log('[#] Stardust: {}'.format(stardust)) logger.log('[#] Pokecoins: {}'.format(pokecoins)) logger.log('[#] PokeBalls: ' + str(balls_stock[1])) logger.log('[#] GreatBalls: ' + str(balls_stock[2])) logger.log('[#] UltraBalls: ' + str(balls_stock[3])) self.get_player_info() if self.config.initial_transfer: worker = InitialTransferWorker(self) worker.work() logger.log('[#]') self.update_inventory()
def _print_character_info(self): # get player profile call # ---------------------- response_dict = self.api.get_player() # print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2))) currency_1 = "0" currency_2 = "0" if response_dict: self._player = response_dict['responses']['GET_PLAYER']['player_data'] player = self._player else: self.logger.info( "The API didn't return player info, servers are unstable - " "retrying.", 'red' ) sleep(5) self._print_character_info() # @@@ TODO: Convert this to d/m/Y H:M:S creation_date = datetime.datetime.fromtimestamp( player['creation_timestamp_ms'] / 1e3) creation_date = creation_date.strftime("%Y/%m/%d %H:%M:%S") pokecoins = '0' stardust = '0' items_inventory = inventory.items() if 'amount' in player['currencies'][0]: pokecoins = player['currencies'][0]['amount'] if 'amount' in player['currencies'][1]: stardust = player['currencies'][1]['amount'] self.logger.info('') self.logger.info('--- {username} ---'.format(**player)) self.logger.info( 'Pokemon Bag: {}/{}'.format( inventory.Pokemons.get_space_used(), inventory.get_pokemon_inventory_size() ) ) self.logger.info( 'Items: {}/{}'.format( inventory.Items.get_space_used(), inventory.get_item_inventory_size() ) ) self.logger.info( 'Stardust: {}'.format(stardust) + ' | Pokecoins: {}'.format(pokecoins) ) # Items Output self.logger.info( 'PokeBalls: ' + str(items_inventory.get(1).count) + ' | GreatBalls: ' + str(items_inventory.get(2).count) + ' | UltraBalls: ' + str(items_inventory.get(3).count) + ' | MasterBalls: ' + str(items_inventory.get(4).count)) self.logger.info( 'RazzBerries: ' + str(items_inventory.get(701).count) + ' | BlukBerries: ' + str(items_inventory.get(702).count) + ' | NanabBerries: ' + str(items_inventory.get(703).count)) self.logger.info( 'LuckyEgg: ' + str(items_inventory.get(301).count) + ' | Incubator: ' + str(items_inventory.get(902).count) + ' | TroyDisk: ' + str(items_inventory.get(501).count)) self.logger.info( 'Potion: ' + str(items_inventory.get(101).count) + ' | SuperPotion: ' + str(items_inventory.get(102).count) + ' | HyperPotion: ' + str(items_inventory.get(103).count) + ' | MaxPotion: ' + str(items_inventory.get(104).count)) self.logger.info( 'Incense: ' + str(items_inventory.get(401).count) + ' | IncenseSpicy: ' + str(items_inventory.get(402).count) + ' | IncenseCool: ' + str(items_inventory.get(403).count)) self.logger.info( 'Revive: ' + str(items_inventory.get(201).count) + ' | MaxRevive: ' + str(items_inventory.get(202).count)) self.logger.info('')