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

Reduce number of inventory calls #1231

Merged
merged 1 commit into from
Jul 27, 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
27 changes: 13 additions & 14 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, config):
self.pokemon_list = json.load(open(os.path.join('data', 'pokemon.json')))
self.item_list = json.load(open(os.path.join('data', 'items.json')))
self.metrics = Metrics(self)
self.latest_inventory = None

def start(self):
self._setup_logging()
Expand Down Expand Up @@ -313,15 +314,20 @@ def _print_character_info(self):

logger.log('')


def use_lucky_egg(self):
self.api.use_item_xp_boost(item_id=301)
inventory_req = self.api.call()
return inventory_req

def get_inventory(self):
if self.latest_inventory is None:
self.api.get_inventory()
response = self.api.call()
self.latest_inventory = response
return self.latest_inventory

def update_inventory(self):
self.api.get_inventory()
response = self.api.call()
response = self.get_inventory()
self.inventory = list()
if 'responses' in response:
if 'GET_INVENTORY' in response['responses']:
Expand All @@ -344,9 +350,7 @@ def update_inventory(self):
'item'])

def current_inventory(self):
self.api.get_player().get_inventory()

inventory_req = self.api.call()
inventory_req = self.get_inventory()
inventory_dict = inventory_req['responses']['GET_INVENTORY'][
'inventory_delta']['inventory_items']

Expand All @@ -371,9 +375,7 @@ def current_inventory(self):
return items_stock

def item_inventory_count(self, id):
self.api.get_player().get_inventory()

inventory_req = self.api.call()
inventory_req = self.get_inventory()
inventory_dict = inventory_req['responses'][
'GET_INVENTORY']['inventory_delta']['inventory_items']

Expand Down Expand Up @@ -480,14 +482,12 @@ def heartbeat(self):
if timeout >= time.time() * 1000}
self.api.get_player()
self.api.get_hatched_eggs()
self.api.get_inventory()
self.api.check_awarded_badges()
self.api.call()
self.update_web_location() # updates every tick

def get_inventory_count(self, what):
self.api.get_inventory()
response_dict = self.api.call()
response_dict = self.get_inventory()
if 'responses' in response_dict:
if 'GET_INVENTORY' in response_dict['responses']:
if 'inventory_delta' in response_dict['responses'][
Expand Down Expand Up @@ -517,8 +517,7 @@ def get_inventory_count(self, what):
return '0'

def get_player_info(self):
self.api.get_inventory()
response_dict = self.api.call()
response_dict = self.get_inventory()
if 'responses' in response_dict:
if 'GET_INVENTORY' in response_dict['responses']:
if 'inventory_delta' in response_dict['responses'][
Expand Down
9 changes: 3 additions & 6 deletions pokemongo_bot/cell_workers/evolve_all_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def work(self):
if not self._should_run():
return

self.api.get_inventory()
response_dict = self.api.call()
response_dict = self.bot.get_inventory()
cache = {}

try:
Expand Down Expand Up @@ -85,8 +84,7 @@ def _should_run(self):
return skip_evolves

def _release_evolved(self, release_cand_list_ids):
self.api.get_inventory()
response_dict = self.api.call()
response_dict = self.bot.get_inventory()
cache = {}

try:
Expand Down Expand Up @@ -180,8 +178,7 @@ def transfer_pokemon(self, pid):
response_dict = self.api.call()

def count_pokemon_inventory(self):
self.api.get_inventory()
response_dict = self.api.call()
response_dict = self.bot.get_inventory()
id_list = []
return self.counting_pokemon(response_dict, id_list)

Expand Down
7 changes: 3 additions & 4 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ def work(self):
time.sleep(5)

def _transfer_low_cp_pokemon(self, value):
self.api.get_inventory()
response_dict = self.api.call()
response_dict = self.bot.get_inventory()
self._transfer_all_low_cp_pokemon(value, response_dict)

def _transfer_all_low_cp_pokemon(self, value, response_dict):
Expand Down Expand Up @@ -257,8 +256,8 @@ def transfer_pokemon(self, pid):
response_dict = self.api.call()

def count_pokemon_inventory(self):
self.api.get_inventory()
response_dict = self.api.call()
self.bot.latest_inventory = None # Need accurate count of balls/berries/pokemons
response_dict = self.bot.get_inventory()
id_list = []
return self.counting_pokemon(response_dict, id_list)

Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def work(self):

items_awarded = spin_details.get('items_awarded', False)
if items_awarded:
self.bot.latest_inventory = None
tmp_count_items = {}
for item in items_awarded:
item_id = item['item_id']
Expand Down