" place_types = next((t for t in place_details.get(\"types\", []) if t not in [\"food\", \"point_of_interest\"]), \"N/A\") # Get the first type of the place, excluding \"food\" and \"point_of_interest\"\n",
" place_rating = place_details.get(\"rating\", \"N/A\") # Get the rating of the place\n",
" total_ratings = place_details.get(\"user_ratings_total\", \"N/A\") # Get the total number of ratings\n",
" place_address = place_details.get(\"vicinity\", \"N/A\") # Get the vicinity of the place\n",
"\n",
"\n",
" if ',' in place_address: # If the address contains a comma\n",
" street_address = place_address.split(',')[0] # Split by comma and keep only the first part\n",
" else:\n",
" street_address = place_address\n",
"\n",
"\n",
" # Prepare the output string for this place\n",
" place_info = f\"{place_name} is a {place_types} located at {street_address}. It has a rating of {place_rating} based on {total_ratings} user reviews.\"\n",
"\n",
"\n",
" places.append(place_info)\n",
"\n",
" return places\n",
@ -203,7 +206,7 @@
" return []\n",
" except Exception as e:\n",
" print(f\"Error during the Google Places API call: {e}\")\n",
" if places: # If the list of places is not empty\n",
" return f\"Here are some places you might be interested in: {' '.join(places)}\"\n",
@ -297,22 +302,23 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here are some places you might be interested in: Mona Lisa Restaurant is a restaurant located at 353 Columbus Avenue #3907. It has a rating of 4.3 based on 1784 user reviews. Tommaso's Ristorante Italiano is a restaurant located at 1042 Kearny Street. It has a rating of 4.5 based on 732 user reviews.\n"