<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
from scipy.stats import linregress
from urllib.request import urlretrieve
from urllib.parse import urlencode

# Import API key
from api_keys import weather_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)<jupyter_output><empty_output><jupyter_text>Generate Cities List<jupyter_code>#generate random list for latitudes and longitudes 

latitude = []
longitude = []
max_num=5
for each_lat in np.random.randint(-90,90,max_num):
    latitude.append(each_lat)

for each_lon in np.random.randint(-180,180,max_num):
    longitude.append(each_lon)<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>latitude_and_Longitude = tuple(zip(latitude,longitude))
latitude_and_Longitude<jupyter_output><empty_output><jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>cities = []
country = []

for lat,lon in latitude_and_Longitude:
    city = citipy.nearest_city(lat,lon)
    
    cityName = city.city_name
    
    cities.append(cityName)
    
    country.append(city.country_code)
    
print('The above script has generated {} different cities using random numbers.'.format(len(set(cities))))
cities
#create a dataframe to store all the cities and countries generated with citipy

df_countriesf_countries = pd.DataFrame({'Cities': cities,
              'Country': country})

#add additional blank columns to store information from openweathermap api

df_countries['Latitude'] = ''
df_countries['Longitude'] = ''
df_countries['Temperature (F)'] = ''
df_countries['Humidity (%)'] = ''
df_countries['Cloudiness (%)'] = ''
df_countries['Wind Speed (mph)'] = ''

df_countries = df_countries.drop_duplicates(subset=['Cities'],keep='first')
print(df_countriesf_countries)

api_key = "<KEY>"


apikey = '<KEY>'
url = "http://api.openweathermap.org/data/2.5/weather?"
units = "Imperial"
count = 0
df_countriesf_countries['latitude'] = ""
df_countriesf_countries['temperature'] = ""
df_countriesf_countries['humidity'] = ""
df_countriesf_countries['cloudiness'] = ""
df_countriesf_countries['wind_speed'] = ""
df_countriesf_countries['returncode'] = ""
df_countriesf_countries['Longitude'] = ""
for index,row in df_countriesf_countries.iterrows():
    count += 1
    query_url = url + "appid=" + apikey + "&units=" + units + "&q=" + row['Cities']
    
    print(f"{query_url}\n{count} index {index} ")
    try:
        weather_response = requests.get(query_url)
        cityweather = weather_response.json()
        #print(f"hi there {query_url}")
        #if count < 5 : 
        #print(f" ha ha {cityweather}")
        #df_countriesf_countries
        retCode=weather_response.status_code
        #print()
        print(f" this is it {retCode}")
        df_countriesf_countries['returncode'][index] = str(retCode)
        if int(retCode) == 200: 
            df_countriesf_countries['latitude'][index] = cityweather['coord']['lat']
            df_countriesf_countries['Longitude'][index] = cityweather['coord']['lat']
            df_countriesf_countries['temperature'][index] = cityweather['main']['temp']
            df_countriesf_countries['humidity'][index] = cityweather['main']['humidity']
            df_countriesf_countries['cloudiness'][index] = cityweather['clouds']['all']
            df_countriesf_countries['wind_speed'][index] = cityweather['wind']['speed']
            #print(df_countriesf_countries['latitude'][index])
        else:
            print(f" {retCode} is not 200 ")
        #df_countries.set_value(index, "latitude", int(cityweather['coord']['lat']))
        #df_countries.set_value(index, "longitude", int(cityweather['coord']['lat']))
        #df_countries.set_value(index, "temperature", int(cityweather['main']['temp']))
        #df_countries.set_value(index, "humidity", int(cityweather['main']['humidity']))
        #df_countries.set_value(index, "cloudiness", int(cityweather['clouds']['all']))
        #df_countries.set_value(index, "wind_speed", int(cityweather['wind']['speed']))
    except requests.exceptions.HTTPError as e:
        print(f"No data for this city: {row['city']} returned code {e}")
        #print(f"No data for this city: {row['Cities']}")
    #print(f"This is city#: {count}")
    #print(f"This is: {row['Cities']}" )
    #print(f"This is the requested URL: {query_url}")
    #print(f" lattitude {cityweather['coord']['lat']}")
df_countriesf_countries.head()<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>df_countries['Cities'].iloc[0]
df_countries.len()<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot  Latitude vs. Cloudiness Plot  Latitude vs. Wind Speed Plot  Linear Regression<jupyter_code># OPTIONAL: Create a function to create Linear Regression plots

# Create Northern and Southern Hemisphere DataFrames<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12827271129854156, 'fraction_numerical': 0.005798629414865577, 'mean_word_length': 5.042462845010616, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '539474', 'license': 'ADSL', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1821, 'n_words': 421, 'path': 'starter_code/.ipynb_checkpoints/WeatherPy-checkpoint.ipynb', 'repo_name': 'atulbhingarde/DATA-06', 'size': '5745'}