<jupyter_start><jupyter_text>VacationPy---- Note* Keep an eye on your API usage. Use https://developers.google.com/maps/reporting/gmp-reporting as reference for how to monitor your usage and billing.* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps.<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import gmaps
import os
from pprint import pprint

# Import API key
from api_keys import g_key<jupyter_output><empty_output><jupyter_text>Store Part I results into DataFrame* Load the csv exported in Part I to a DataFrame<jupyter_code># Load csv
weather_file = "../WeatherPy/WeatherPY3.csv"

# Read and display csv with Pandas
weather_df = pd.read_csv(weather_file)
weather_df.head()<jupyter_output><empty_output><jupyter_text>Humidity Heatmap* Configure gmaps.* Use the Lat and Lng as locations and Humidity as the weight.* Add Heatmap layer to map.<jupyter_code># Configure gmaps
gmaps.configure(api_key=g_key)

#Determine max Humidity
humidity_max=weather_df['Humidity'].max()
humidity_max
# Store latitude and longitude in locations
locations = weather_df[["Lat", "Lng"]]
# locations
rating = weather_df["Humidity"].astype(float)    
# Plot heatmap
fig = gmaps.figure()

# Create heat layer
heat_layer = gmaps.heatmap_layer(locations, weights=rating, dissipating=False, max_intensity=100, point_radius=1)

# Add layer
fig.add_layer(heat_layer)

# Display figure
fig<jupyter_output><empty_output><jupyter_text>Create new DataFrame fitting weather criteria* Narrow down the cities to fit weather conditions.* Drop any rows will null values.<jupyter_code># Create a dataframe narrowing down cities to fit my very broad definition of ideal weather locations for a vacation. 
hotel_df= weather_df[(weather_df["Max Temp"]>60) & (weather_df["Max Temp"]<=90) & (weather_df["Humidity"]>=30) & (weather_df["Humidity"]<=60) & (weather_df["Cloudiness"]<60)]
hotel_df<jupyter_output><empty_output><jupyter_text>Hotel Map* Store into variable named `hotel_df`.* Add a "Hotel Name" column to the DataFrame.* Set parameters to search for hotels with 5000 meters.* Hit the Google Places API for each city's coordinates.* Store the first Hotel result into the DataFrame.* Plot markers on top of the heatmap.<jupyter_code># Add a "Hotel Name" column to dataframe
hotel_df["Hotel Name"] = ""
hotel_df.head()

# Set parameters to search for a hotel
params = {
    "radius": 5000,
    "types": "lodging",
    "key": g_key
}

# Iterate through 
for index, row in hotel_df.iterrows():
    # get lat, lng from df
    lat = row["Lat"]
    lng = row["Lng"]
    
    params["location"] = f"{lat},{lng}"
    
    # Use the search term: "Hotel" and our lat/lng
    base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

    # make request and print url
    name_address = requests.get(base_url, params=params)
    
    # convert to json
    name_address = name_address.json()
    
    # Grab the first hotel from the results and store the name
    try:
        hotel_df.loc[index, "Hotel Name"] = name_address["results"][0]["name"]
    except (KeyError, IndexError):
        print("Missing field/result... skipping.")

hotel_df
# NOTE: Do not change any of the code in this cell

# Using the template add the hotel marks to the heatmap
info_box_template = """
<dl>
<dt>Name</dt><dd>{Hotel Name}</dd>
<dt>City</dt><dd>{City}</dd>
<dt>Country</dt><dd>{Country}</dd>
</dl>
"""
# Store the DataFrame Row
# NOTE: be sure to update with your DataFrame name
hotel_info = [info_box_template.format(**row) for index, row in hotel_df.iterrows()]
locations = hotel_df[["Lat", "Lng"]]
#Convert "Hotel Name" column from the hotel_df to a list
hotels= hotel_df["Hotel Name"].tolist()
hotels
# Create a map with markers of hotel locations
hotel_layer = gmaps.marker_layer(locations)
fig = gmaps.figure()
fig.add_layer(hotel_layer)

#Display map
fig
# Add marker layer ontop of heat map
fig=gmaps.figure()
fig.add_layer(heat_layer)
fig.add_layer(hotel_layer)

# Display figure
fig

  #  locations, fill_color='rgba(0, 150, 0, 0.4)',
   # stroke_color='rgba(0, 0, 150, 0.4)', scale=2,
  #  info_box_content=[f"Hotels: {hotels}" for Name in hotel_info]

#gmaps.configure(api_key=g_key)


# for idx, each_row in hotel_df.iterrows():
#     complete_url= f'{base_url}address={cities}&key=g_key'
#     response=requests.get(complete_url)
#     data=response.json()





# base_url= "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
#response = requests.get(f"http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={weather_api_key}&units=Imperial").json()
 #       city.append(response['name'])
#for idx, each_row in hotel_df.head(5).iterrows():
  
#     query_param= {
#     'key': g_key,
#     'location':f"{each_row['Lat'], each_row['Lng']}",
#     'radius': 5000,
#     'type': 'lodging'
# }
# response=requests.get(base_url, query_param)
    
    
#complete_url=f'{base_url}address={each_row["City"]}, {each_row["State"]}&key={g_key}'
#data=response.json(),

# query_url= (f"{base_url}, {query_param}, &key={g_key}")

# response = requests.get(f"{query_url}&key={g_key}")
#response= requests.get(base_url, query_param, g_key)
# params = {
#     "radius": 5000,
#     "types": "lodging",
#     "key": g_key
# }

# # Iterate through 
# for index, row in hotel_df.iterrows():
#     # get lat, lng from df
#     lat = row["Lat"]
#     lng = row["Lng"]
    
#     params["location"] = f"{lat},{lng}"
#     base_url= "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
#     response = requests.get(base_url, params=params)  
#     data=response.json()
    
#     try: 
#         row.loc[index, "Hotel Name"]= data["results"][0]["name"]
#     except: 
#         print("City not found. Skipping...")
#         pass 
# hotel_df.head()

#for idx, each_row in weather_df.iterrows():
# params = {
 #   "radius": target_radius
#}
# lat= hotel_df.loc['Lat']
# lng= hotel_df.loc['Lng']
#city_name= hotel_df['City']
# query_params={
#     'key': g_key,
#    # 'location': city,
#     'radius': 5000,
#     'types': 'lodging'   
# }

# for idx, each_row in hotel_df.iterrows():
#     try:
#         lat= each_row["Lat"]
#         lon= each_row["Lng"]
#         #city= (f"{lat},{lon}")
#         query_params['location'] = f"{lat},{lng}"
#         base_url= "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
#         response = requests.get(base_url, params=query_params)  
#         data=response.json()
#         each_row.loc[index, "Hotel Name"]= data["results"][0]["name"]
#     except: 
#         print("City not found. Skipping...")
#         pass 
# hotel_df.head()
# # city=city_name.tolist()

# # base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

# base_url= "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
# for idx, each_row in hotel_df.iterrows():
#     try:
#         lat= each_row["Lat"]
#         lon= each_row["Lng"]
#         city= (f"{lat},{lon}")

#         query_params={
#             'key': g_key,
#         #    'location': city,
#             'radius': 5000,
#             'types': 'lodging'  
#         }
#         response = requests.get(base_url, params=query_params)  
#         data=response.json()
        
        
#         each_row.loc[index, "Hotel Name"]= data["results"][0]["name"]
#        # hotel_name= each_row["Hotel Name"]
#     except: 
#         print("City not found. Skipping...")
#         pass 

# # for idx, each_row in hotel_df.iterrows():
# #     lat= each_row["Lat"]
# #     lon= each_row["Lng"]
# #     city= (f"{lat},{lon}")

# #     query_params={
# #     'key': g_key,
# #     'location': city,
# #     'radius': 5000,
# #     'types': 'lodging'   
# #     }

# #     base_url= "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?"
# #     response = requests.get(base_url, params=query_params)  
# #     data=response.json()

# #     try:
# #         each_row.loc[index, "Hotel Name"]= data["results"][0]["name"]
# # #hotel_name= each_row["Hotel Name"]
# #     except: 
# #         print("City not found. Skipping...")
# #         pass 
# hotel_df.head()

#     # hotel_name= each_row["Hotel Name"]
    
# #pprint(data)
#  #   response=requests.get(complete_url)
    
    
# #query_param
# # for idx, each_row in hotel_df(3).iterrows():
# #     complete_url=f'{base_url}{query_param}'

# # for idx, each_row in hotel_df():

# # for idx, each_row in hotel_df(3).iterrows():
# #     query_param={
# #         'key': g_key,
# #         'location': {each_row['City']},
# #         'radius': 5000,
# #         'type': 'lodging'
# #     }

# #response=requests.get(base_url, query_param)

#    # 'location': {each_row['City']},
# # pprint(response.json())
# #response=requests.get(gmaps.configure(api_key=g_key))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1548855388051368, 'fraction_numerical': 0.008040201005025126, 'mean_word_length': 3.7511936339522545, 'pattern_counts': {'":': 7, '<': 38, '<?xml version=': 0, '>': 37, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '499574', 'license': 'ADSL', 'n_tokens_mistral': 3234, 'n_tokens_neox': 3122, 'n_words': 720, 'path': 'Vacation Py/VacationPy.ipynb', 'repo_name': 'LisaCaruana/Python-api-challenge', 'size': '8955'}