Created
January 30, 2020 12:07
-
-
Save drewsonne/553be3f766d410b09a012a25780c2eb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pages(): | |
if response.get('next_page_token') is not None: | |
self.logger.debug('More than 20 results found, paging Dr. Token') | |
results = response['results'] | |
page_token = response['next_page_token'] | |
while page_token is not None: | |
try: | |
response = self.client.places_nearby(page_token=page_token) | |
except googlemaps.exceptions.ApiError as e: # Requesting page before it's available will trigger this exception so we wait | |
self.logger.debug(e) | |
self.logger.warning('Token is not ready, waiting 2 seconds') | |
sleep(2) | |
response = self.client.places_nearby(page_token=page_token) | |
yield response['results'] | |
page_token = response.get('next_page_token') | |
return results | |
else: | |
self.logger.info(json.dumps(response['results'])) | |
yield response['results'] | |
results = [] | |
for page in pages(): | |
results.append(page) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment