From 8f03bf8cbd567c2f9e12019956559772ed3ca41f Mon Sep 17 00:00:00 2001 From: Eli White Date: Sat, 30 Jul 2016 15:16:43 -0700 Subject: [PATCH] Making the navigators workers --- pokemongo_bot/__init__.py | 5 ++-- pokemongo_bot/cell_workers/__init__.py | 2 ++ .../follow_path.py} | 28 +++++++++---------- .../follow_spiral.py} | 28 +++++++++---------- pokemongo_bot/navigators/__init__.py | 2 -- 5 files changed, 30 insertions(+), 35 deletions(-) rename pokemongo_bot/{navigators/path_navigator.py => cell_workers/follow_path.py} (76%) rename pokemongo_bot/{navigators/spiral_navigator.py => cell_workers/follow_spiral.py} (77%) delete mode 100644 pokemongo_bot/navigators/__init__.py diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 53ef7ccffa..c41f930ab5 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -15,7 +15,6 @@ import cell_workers import logger -import navigators from api_wrapper import ApiWrapper from cell_workers.utils import distance from event_manager import EventManager @@ -55,9 +54,9 @@ def start(self): self._setup_workers() if self.config.navigator_type == 'spiral': - self.navigator=navigators.SpiralNavigator(self) + self.navigator=cell_workers.FollowSpiral(self) elif self.config.navigator_type == 'path': - self.navigator=navigators.PathNavigator(self) + self.navigator=cell_workers.FollowPath(self) random.seed() diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index a0464168c6..8a700ef5ba 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -10,3 +10,5 @@ from recycle_items import RecycleItems from spin_fort import SpinFort from handle_soft_ban import HandleSoftBan +from follow_path import FollowPath +from follow_spiral import FollowSpiral diff --git a/pokemongo_bot/navigators/path_navigator.py b/pokemongo_bot/cell_workers/follow_path.py similarity index 76% rename from pokemongo_bot/navigators/path_navigator.py rename to pokemongo_bot/cell_workers/follow_path.py index 634d52a51e..ebc77cfe90 100644 --- a/pokemongo_bot/navigators/path_navigator.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -10,23 +10,21 @@ from pgoapi.utilities import f2i -class PathNavigator(object): +class FollowPath(object): def __init__(self, bot): self.bot = bot - self.api = bot.api - self.config = bot.config self.ptr = 0 self.points = self.load_path() def load_path(self): - if self.config.navigator_path_file == None: + if self.bot.config.navigator_path_file == None: raise RuntimeError('You need to specify a path file (json or gpx)') - if self.config.navigator_path_file.endswith('.json'): - return self.load_json(self.config.navigator_path_file) - elif self.config.navigator_path_file.endswith('.gpx'): - return self.load_gpx(self.config.navigator_path_file) + if self.bot.config.navigator_path_file.endswith('.json'): + return self.load_json(self.bot.config.navigator_path_file) + elif self.bot.config.navigator_path_file.endswith('.gpx'): + return self.load_gpx(self.bot.config.navigator_path_file) def load_json(self, file): with open(file) as data_file: @@ -63,10 +61,10 @@ def take_step(self): lat = float(point['lat']) lng = float(point['lng']) - if self.config.walk > 0: + if self.bot.config.walk > 0: step_walker = StepWalker( self.bot, - self.config.walk, + self.bot.config.walk, lat, lng ) @@ -76,19 +74,19 @@ def take_step(self): is_at_destination = True else: - self.api.set_position(lat, lng) + self.bot.api.set_position(lat, lng) dist = distance( - self.api._position_lat, - self.api._position_lng, + self.bot.api._position_lat, + self.bot.api._position_lng, lat, lng ) - if dist <= 1 or (self.config.walk > 0 and is_at_destination): + if dist <= 1 or (self.bot.config.walk > 0 and is_at_destination): if (self.ptr + 1) == len(self.points): self.ptr = 0 - if self.config.navigator_path_mode == 'linear': + if self.bot.config.navigator_path_mode == 'linear': self.points = list(reversed(self.points)) else: self.ptr += 1 diff --git a/pokemongo_bot/navigators/spiral_navigator.py b/pokemongo_bot/cell_workers/follow_spiral.py similarity index 77% rename from pokemongo_bot/navigators/spiral_navigator.py rename to pokemongo_bot/cell_workers/follow_spiral.py index e91e93fbd0..6d4d6d0ed2 100644 --- a/pokemongo_bot/navigators/spiral_navigator.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -5,13 +5,11 @@ from pokemongo_bot.step_walker import StepWalker -class SpiralNavigator(object): +class FollowSpiral(object): def __init__(self, bot): self.bot = bot - self.api = bot.api - self.config = bot.config - self.steplimit = self.config.max_steps + self.steplimit = self.bot.config.max_steps self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1] @@ -59,38 +57,38 @@ def take_step(self): point = self.points[self.ptr] self.cnt += 1 - if self.config.walk > 0: + if self.bot.config.walk > 0: step_walker = StepWalker( self.bot, - self.config.walk, + self.bot.config.walk, point['lat'], point['lng'] ) dist = distance( - self.api._position_lat, - self.api._position_lng, + self.bot.api._position_lat, + self.bot.api._position_lng, point['lat'], point['lng'] ) if self.cnt == 1: logger.log( - 'Walking from ' + str((self.api._position_lat, - self.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist, - self.config.distance_unit)) + 'Walking from ' + str((self.bot.api._position_lat, + self.bot.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist, + self.bot.config.distance_unit)) if step_walker.step(): step_walker = None else: - self.api.set_position(point['lat'], point['lng']) + self.bot.api.set_position(point['lat'], point['lng']) if distance( - self.api._position_lat, - self.api._position_lng, + self.bot.api._position_lat, + self.bot.api._position_lng, point['lat'], point['lng'] - ) <= 1 or (self.config.walk > 0 and step_walker == None): + ) <= 1 or (self.bot.config.walk > 0 and step_walker == None): if self.ptr + self.direction == len(self.points) or self.ptr + self.direction == -1: self.direction *= -1 self.ptr += self.direction diff --git a/pokemongo_bot/navigators/__init__.py b/pokemongo_bot/navigators/__init__.py deleted file mode 100644 index 3611385377..0000000000 --- a/pokemongo_bot/navigators/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from spiral_navigator import SpiralNavigator -from path_navigator import PathNavigator