From dfa4f78f85e391e7bc9c6757478e68f724e108fc Mon Sep 17 00:00:00 2001 From: Ovidiu Ghinet Date: Fri, 29 Jul 2016 14:10:09 +0200 Subject: [PATCH] Fixed args PolylineWalker to match the super StepWalker class (#1621) * * Removed pokemongo_bot/polyline_stepper.py - old Stepper() class * Fixed args PolylineWalker to match the super StepWalker class * Added a check to Polynine() point tinitalization, if no route was found then, we will return no points between orig, dest thus will walk in straight line - expected behaviour will teleport in small steps * * fix typo --- pokemongo_bot/polyline_stepper.py | 40 --------------------- pokemongo_bot/walkers/polyline_generator.py | 8 +++-- pokemongo_bot/walkers/polyline_walker.py | 8 ++--- 3 files changed, 9 insertions(+), 47 deletions(-) delete mode 100644 pokemongo_bot/polyline_stepper.py diff --git a/pokemongo_bot/polyline_stepper.py b/pokemongo_bot/polyline_stepper.py deleted file mode 100644 index af701cc0d3..0000000000 --- a/pokemongo_bot/polyline_stepper.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -from math import ceil - -import logger -from human_behaviour import sleep -from walkers.polyline_walker import PolylineWalker - - -class PolylineStepper(Stepper): - - 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, 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: - logger.log('[#] Using _old_walk_to to go to the proposed_origin: {}' - .format(proposed_origin)) - self._old_walk_to(speed, proposed_lat, proposed_lng, alt) - if proposed_origin != proposed_destination: - duration = polyline_walker.get_total_distance() / speed - logger.log('[#] Using PolylineWalker from {} to {} for approx. {} seconds.' - .format(proposed_origin, proposed_destination, ceil(duration))) - 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(self.api._position_lat, 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: - logger.log('[#] Using _old_walk_to to go from the proposed destination : {} to {}' - .format(proposed_destination, (lat, lng))) - - self._old_walk_to(speed, lat, lng, alt) - - def _old_walk_to(self, speed, lat, lng, alt): - return super(PolylineStepper, self)._walk_to(speed, lat, lng, alt) diff --git a/pokemongo_bot/walkers/polyline_generator.py b/pokemongo_bot/walkers/polyline_generator.py index ff50885b98..da5adfdaad 100644 --- a/pokemongo_bot/walkers/polyline_generator.py +++ b/pokemongo_bot/walkers/polyline_generator.py @@ -15,8 +15,12 @@ def __init__(self, origin, destination, speed): self.URL = '{}&origin={}&destination={}'.format(self.DISTANCE_API_URL, '{},{}'.format(*self.origin), '{},{}'.format(*self.destination)) - self.polyline_points = [x['polyline']['points'] for x in - requests.get(self.URL).json()['routes'][0]['legs'][0]['steps']] + self.request_responce = requests.get(self.URL).json() + try: + self.polyline_points = [x['polyline']['points'] for x in + self.request_responce['routes'][0]['legs'][0]['steps']] + except IndexError: + self.polyline_points = self.request_responce['routes'] self.speed = float(speed) self.points = [self.origin] + self.get_points(self.polyline_points) + [self.destination] self.lat, self.long = self.points[0][0], self.points[0][1] diff --git a/pokemongo_bot/walkers/polyline_walker.py b/pokemongo_bot/walkers/polyline_walker.py index a942195f50..9be275785c 100644 --- a/pokemongo_bot/walkers/polyline_walker.py +++ b/pokemongo_bot/walkers/polyline_walker.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- from polyline_generator import Polyline -from math import ceil from pokemongo_bot.human_behaviour import sleep -from pokemongo_bot.cell_workers.utils import i2f from pokemongo_bot.step_walker import StepWalker from pokemongo_bot import logger class PolylineWalker(StepWalker): - def __init__(self, bot, speed, initLat, initLng, destLat, destLng): - super(PolylineWalker, self).__init__(bot, speed, initLat, initLng, destLat, destLng) - self.polyline_walker = Polyline((i2f(self.api._position_lat), i2f(self.api._position_lng)), + def __init__(self, bot, speed, destLat, destLng): + super(PolylineWalker, self).__init__(bot, speed, destLat, destLng) + self.polyline_walker = Polyline((self.api._position_lat, self.api._position_lng), (self.destLat, self.destLng), self.speed) logger.log('[#] {}'.format(self.polyline_walker.URL))