<jupyter_start><jupyter_text>WeatherPy---- Note* 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 time

# Import API key
from api_keys import api_key

# Incorporated citipy to determine city based on latitude and longitude
from citipy import citipy

# Output File (CSV)
output_data_file = "output_data/cities.csv"

# Range of latitudes and longitudes
lat_range = (-90, 90)
lng_range = (-180, 180)
api_key<jupyter_output><empty_output><jupyter_text>Generate Cities List<jupyter_code># List for holding lat_lngs and cities
lat_lngs = []
cities = []

# Create a set of random lat and lng combinations
lats = np.random.uniform(low=-90.000, high=90.000, size=1500)
lngs = np.random.uniform(low=-180.000, high=180.000, size=1500)
lat_lngs = zip(lats, lngs)

# Identify nearest city for each lat, lng combination
for lat_lng in lat_lngs:
    city = citipy.nearest_city(lat_lng[0], lat_lng[1]).city_name
    
    # If the city is unique, then add it to a our cities list
    if city not in cities:
        cities.append(city)

# Print the city count to confirm sufficient count
len(cities)
cities<jupyter_output><empty_output><jupyter_text>Perform API Calls* Perform a weather check on each city using a series of successive API calls.* Include a print log of each city as it'sbeing processed (with the city number and city name).<jupyter_code>cities
url = "https://api.openweathermap.org/data/2.5/weather?units=Imperial&APPID=" + api_key
city_weather_list = []

print("Beginning Data Retrieval")    
print("-----------------------------")
record = 1
setcount = 1
for i, city in enumerate(cities):
    url_per_city = url + "&q=" + city

    if (i % 50 == 0 and i>=50):
        setcount = setcount + 1
        record = 0
    print(f"Processing Record {record} of Set {setcount} | {city}")
    record = record + 1
    try:
        data = requests.get(url_per_city).json()
        city_name = city
        cloudiness = data['clouds']['all']
        country = data['sys']['country']
        humidity = data['main']['humidity']
        date = data['dt']
        lat = data['coord']['lat']
        lon = data['coord']['lon']
        max_temp = data['main']['temp_max']
        wind_speed = data['wind']['speed']
    
        city_weather_list.append({ "City": city_name,
                                  "Cloudiness": cloudiness,
                                  "Country": country,
                                  "Date" : date,
                                  "Humidity": humidity,
                                  "Lat": lat,
                                  "Lon": lon,
                                   "Max Temp" : max_temp,
                                  "Wind Speed" : wind_speed })
    except:
        print("City not found... Skipping")
        pass

print("-----------------------------")
print("Data Retrieval Complete ")    
print("-----------------------------")<jupyter_output>Beginning Data Retrieval
-----------------------------
Processing Record 1 of Set 1 | codrington
Processing Record 2 of Set 1 | husavik
Processing Record 3 of Set 1 | vangaindrano
Processing Record 4 of Set 1 | arraial do cabo
Processing Record 5 of Set 1 | saint-georges
Processing Record 6 of Set 1 | carnarvon
Processing Record 7 of Set 1 | kapit
Processing Record 8 of Set 1 | urumqi
City not found... Skipping
Processing Record 9 of Set 1 | hilo
Processing Record 10 of Set 1 | bredasdorp
Processing Record 11 of Set 1 | benalla
Processing Record 12 of Set 1 | nanortalik
Processing Record 13 of Set 1 | tiznit
Processing Record 14 of Set 1 | saint-philippe
Processing Record 15 of Set 1 | punta arenas
Processing Record 16 of Set 1 | tasiilaq
Processing Record 17 of Set 1 | abu kamal
Processing Record 18 of Set 1 | mashhad
Processing Record 19 of Set 1 | khuzdar
Processing Record 20 of Set 1 | busselton
Processing Record 21 of Set 1 | hobart
Processing Record 22 of Set 1 | atuona
Processin[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>df = pd.DataFrame(city_weather_list)
df.head(7)
df.to_csv("city_weather_data.csv")<jupyter_output><empty_output><jupyter_text>Plotting the Data* Use proper labeling of the plots using plot titles (including date of analysis) and axes labels.* Save the plotted figures as .pngs.  Latitude vs. Temperature Plot<jupyter_code>lat = df["Lat"]
temp = df["Max Temp"]
plt.scatter(lat, temp, edgecolor = "black")
plt.grid(True)
plt.title("City Latitude vs Max Temperature")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
plt.show()
lat = df["Lat"]
humidity = df["Humidity"]

plt.scatter(lat, humidity, edgecolor = "black")
plt.grid(True)

plt.title("City Latitude vs Humidity")
plt.xlabel("Latitude")
plt.ylabel("Max Humidity (%)")

plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code>lat = df["Lat"]
cloud = df["Cloudiness"]

plt.scatter(lat, cloud, edgecolor = "black")
plt.grid(True)

plt.title("City Latitude vs Humidity")
plt.xlabel("Latitude")
plt.ylabel("Cloudiness (%)")

plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code>lat = df["Lat"]
windsp = df["Wind Speed"]

plt.scatter(lat, windsp, edgecolor = "black")
plt.grid(True)

plt.title("City Latitude vs Humidity")
plt.xlabel("Latitude")
plt.ylabel("Wind Speed (mph)")

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12462006079027356, 'fraction_numerical': 0.02002503128911139, 'mean_word_length': 3.187125748502994, 'pattern_counts': {'":': 6, '<': 28, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '571258', 'license': 'ADSL', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1722, 'n_words': 572, 'path': 'starter_code/WeatherPy.ipynb', 'repo_name': 'pattanyj/Python_Api_Homework', 'size': '5593'}