JourneyJoker/frontend/places/api.py

15 lines
No EOL
603 B
Python

from django.utils.translation import get_language
from django.conf import settings
import googlemaps
from dbsettings.functions import getValue
class GoogleAPI:
def __init__(self, api_key=None):
api_key = api_key or getValue("google.api.key")
self.api = googlemaps.Client(key=api_key)
def autocomplete(self, term, types="(cities)", language=get_language(), countries=settings.JOKER_COUNTRIES):
response = self.api.places_autocomplete(term, types=types, language=language, components={"country": countries})
return [result["description"] for result in response]