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

Polyline handle Google Directions API request exception without raise #5026

Merged
merged 1 commit into from
Sep 1, 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
30 changes: 12 additions & 18 deletions pokemongo_bot/walkers/polyline_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,22 @@ def __init__(self, origin, destination, speed):

self.directions_response = requests.get(self.DIRECTIONS_URL).json()
try:
# Polyline walker starts teleporting after reaching api query limit.
# throw error here atm, catch it at factory and return StepWalker
#
# In case of API limit reached we get back we get a status 200 code with an empty routes []
#
# {u'error_message': u'You have exceeded your rate-limit for this API.',
# u'routes': [],
# u'status': u'OVER_QUERY_LIMIT'
# }

self.polyline_points = [x['polyline']['points'] for x in
self.directions_response['routes'][0]['legs'][0]['steps']]
# This handles both cases:
# a) the above API Quota reached self.directions_response['routes'] = []
# b) ZERO_RESULTS {
# "geocoded_waypoints" : [ {}, {} ],
# "routes" : [],
# "status" : "ZERO_RESULTS"
# }
except IndexError:
# This handles both cases:
# a) In case of API limit reached we get back we get a status 200 code with an empty routes []
# {u'error_message': u'You have exceeded your rate-limit for this API.',
# u'routes': [],
# u'status': u'OVER_QUERY_LIMIT'
# }
# b) In case that google does not have any directions proposals we get:
# ZERO_RESULTS {
# "geocoded_waypoints" : [ {}, {} ],
# "routes" : [],
# "status" : "ZERO_RESULTS"
# }
self.polyline_points = self.directions_response['routes']
raise # catch at factory atm...
self.points = [self.origin] + self.get_points(self.polyline_points) + [self.destination]
self.speed = float(speed)
self.lat, self.long = self.points[0][0], self.points[0][1]
Expand Down
4 changes: 0 additions & 4 deletions pokemongo_bot/walkers/polyline_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from pokemongo_bot.constants import Constants

class PolylineWalker(StepWalker):
'''
Heavy multi-botting can cause issues, since the directions API has limits.
StepWalker is generated by the factory in the case.
'''

def __init__(self, bot, dest_lat, dest_lng):
super(PolylineWalker, self).__init__(bot, dest_lat, dest_lng)
Expand Down
5 changes: 1 addition & 4 deletions pokemongo_bot/walkers/walker_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ def walker_factory(name, bot, dest_lat, dest_lng, dest_alt=None, *args, **kwargs
if 'StepWalker' == name:
ret = StepWalker(bot, dest_lat, dest_lng, dest_alt)
elif 'PolylineWalker' == name:
try:
ret = PolylineWalker(bot, dest_lat, dest_lng)
except:
ret = StepWalker(bot, dest_lat, dest_lng, dest_alt)
ret = PolylineWalker(bot, dest_lat, dest_lng)
return ret