JourneyJoker/frontend/places/api.py

15 lines
603 B
Python
Raw Normal View History

2021-04-17 06:30:26 +00:00
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]