def search_location()

in challenge5/python-backend/app.py [0:0]


def search_location():
    data = request.get_json()
    location = data['location']
    search_query = data['search_query']

    serpApiKey = os.getenv('SERPAPI_API_KEY')
    if not serpApiKey:
      raise ValueError('SERPAPI_API_KEY is not defined')
    
    params = {
        "engine": "google",
        "q": search_query,
        "location": location,
        "api_key": serpApiKey,
        "limit": 5
    }

    search = GoogleSearch(params)
    results = search.get_dict()
    organic_results = results["organic_results"]
    return organic_results