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

Fixed Google geocoding #1600

Merged
merged 1 commit into from
Mar 23, 2020
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
15 changes: 9 additions & 6 deletions cartoframes/data/services/geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,15 @@ def _geocode(self, table_name, street, city=None, state=None, country=None, stat
aborted = False

if not dry_run:
available_quota = self.available_quota()
if output['required_quota'] > available_quota:
raise Exception('Your CARTO account does not have enough Geocoding quota: {}/{}'.format(
output['required_quota'],
available_quota
))
provider = self.provider()

if provider not in ['google']: # Geocoder providers without server quota (use the client API key)
available_quota = self.available_quota()
if output['required_quota'] > available_quota:
raise Exception('Your CARTO account does not have enough Geocoding quota: {}/{}'.format(
output['required_quota'],
available_quota
))

if output['required_quota'] > 0:
with TableGeocodingLock(self._execute_query, table_name) as locked:
Expand Down
4 changes: 4 additions & 0 deletions cartoframes/data/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def _quota_info(self, service):
return {k: row.get(k) for k in QUOTA_INFO_KEYS}
return None

def provider(self):
info = self._quota_info(self._quota_service)
return info and info.get('provider')

def used_quota(self):
info = self._quota_info(self._quota_service)
return info and info.get('used_quota')
Expand Down