From 8203f360feeccd61387e5e3e52c4779c9fdc3e1c Mon Sep 17 00:00:00 2001 From: Eli White Date: Tue, 9 Aug 2016 02:19:31 -0700 Subject: [PATCH] Stop fetching gym details (#3245) --- pokemongo_bot/__init__.py | 18 ------------------ pokemongo_bot/gym_cache.py | 32 -------------------------------- 2 files changed, 50 deletions(-) delete mode 100644 pokemongo_bot/gym_cache.py diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 6f45034f1a..f0f98ba157 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -25,7 +25,6 @@ from human_behaviour import sleep from item_list import Item from metrics import Metrics -from gym_cache import GymCache from pokemongo_bot.event_handlers import LoggingHandler, SocketIoHandler from pokemongo_bot.socketio_server.runner import SocketIoRunner from pokemongo_bot.websocket_remote_control import WebsocketRemoteControl @@ -62,7 +61,6 @@ def __init__(self, config): ) self.item_list = json.load(open(os.path.join('data', 'items.json'))) self.metrics = Metrics(self) - self.gym_cache = GymCache(self) self.latest_inventory = None self.cell = None self.recent_forts = [None] * config.forts_max_circle_size @@ -496,22 +494,6 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None): location = self.position[0:2] cells = self.find_close_cells(*location) - # insert detail info about gym to fort - for cell in cells: - if 'forts' in cell: - for fort in cell['forts']: - if fort.get('type') != 1: - response_gym_details = self.gym_cache.get( - gym_id=fort.get('id'), - player_latitude=lng, - player_longitude=lat, - gym_latitude=fort.get('latitude'), - gym_longitude=fort.get('longitude') - ) - fort['gym_details'] = response_gym_details.get( - 'responses', {} - ).get('GET_GYM_DETAILS', None) - user_data_cells = "data/cells-%s.json" % self.config.username with open(user_data_cells, 'w') as outfile: json.dump(cells, outfile) diff --git a/pokemongo_bot/gym_cache.py b/pokemongo_bot/gym_cache.py deleted file mode 100644 index b7bc7eb1eb..0000000000 --- a/pokemongo_bot/gym_cache.py +++ /dev/null @@ -1,32 +0,0 @@ -import time - -class GymCache(object): - def __init__(self, bot): - self.bot = bot - self.cache = {} - self.cache_length_seconds = 60 * 10 - - def get(self, gym_id, player_latitude, player_longitude, gym_latitude, gym_longitude): - if gym_id not in self.cache: - response_gym_details = self.bot.api.get_gym_details( - gym_id=gym_id, - player_latitude=player_latitude, - player_longitude=player_longitude, - gym_latitude=gym_latitude, - gym_longitude=gym_longitude - ) - - self.cache[gym_id] = response_gym_details - - gym_info = self.cache[gym_id] - gym_info['last_accessed'] = time.time() - - self._remove_stale_gyms() - return gym_info - - def _remove_stale_gyms(self): - for gym_id, gym_details in self.cache.items(): - if gym_details['last_accessed'] < time.time() - self.cache_length_seconds: - del self.cache[gym_id] - -